[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

Re: JavaHL setConfigDirectory() and auth cache problems

From: Daniel Rall <dlr_at_collab.net>
Date: 2006-12-20 22:52:34 CET

On Wed, 20 Dec 2006, C. Michael Pilato wrote:

> Mark Phippard wrote:
> > Also, I do not believe Windows has a HOME variable, so this will
> > probably return a null. There is a HOMEPATH variable. By default,
> > Subversion stores its configuration in %APPDATA%\Subversion. Maybe the
> > function could be enhanced to look for one of these other variables if
> > HOME does not yield a result.
>
> FYI: Our C function svn_user_get_home() checks $HOME on all platforms
> before falling back to apr_uid_homepath_get() (which does OS-specific
> stuff), so there is precedent for doing so elsewhere.

Thanks everyone for the great feedback. How's this look?

[[[
Try hard to provide an appropriate initial config directory.

While 1.4+ native libraries will Do The Right Thing, mixing 1.3-
native libraries with newer Java bytecode will produce a segfault if a
config directory is not provided.

[ in subversion/bindings/java/javahl/ ]

* src/org/tigris/subversion/javahl/SVNClient.java
  Import java.io.File.
  (SVNClient): Set the config directory to
   determineInitialConfigDir(), allowing it to be overridden by
   sub-classes.
  (determineInitialConfigDir): Attempt to determine an initial
   configuration directory, "%APPDATA%\Subversion" on Windows and
   "~/.subversion" on other operating systems.
  (getUserHomeDirectory): Return the absolute path to the current
   user's home directory,
  (getEnv): Attempt to read an environment variable, something which
   is not possible with most JREs (1.5 re-introduced this
   functionality).
  (isOSWindows): Return whether we're running on Windows.
]]]

Index: subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/SVNClient.java
===================================================================
--- subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/SVNClient.java (revision 22774)
+++ subversion/bindings/java/javahl/src/org/tigris/subversion/javahl/SVNClient.java (working copy)
@@ -18,6 +18,7 @@
  * @endcopyright
  */
 
+import java.io.File;
 import java.io.OutputStream;
 
 /**
@@ -45,18 +46,99 @@
         // Ensure that Subversion's config file area and templates exist.
         try
         {
- // Passing an empty string instead of null (which would be
- // more appropriate) prevents earlier versions of the
- // native library (mismatched from the Java bytecode
- // version) from crashing.
- setConfigDirectory("");
+ setConfigDirectory(determineInitialConfigDir());
         }
         catch (ClientException suppressed)
         {
             // Not an exception-worthy problem, continue on.
         }
     }
+
     /**
+ * Attempt to determine an initial configuration directory,
+ * <code>%APPDATA%\Subversion</code> on Windows and
+ * <code>~/.subversion</code> on other operating systems.
+ *
+ * @return The initial configuration directory, or
+ * <code>null</code> to use the library default. Note that native
+ * library versions older than 1.4 may segfault if we return
+ * <code>null</code>.
+ */
+ protected String determineInitialConfigDir()
+ {
+ String path;
+ if (isOSWindows())
+ {
+ // On Windows, use the %APPDATA%\Subversion directory.
+ path = getEnv("APPDATA");
+ if (path == null)
+ {
+ path = getUserHomeDirectory();
+ if (path != null)
+ {
+ path = new File(path, "Application Data").getPath();
+ }
+ }
+
+ if (path != null)
+ {
+ path = new File(path, "Subversion").getAbsolutePath();
+ }
+ }
+ else
+ {
+ // Everywhere else, use the ~/.subversion directory.
+ path = getUserHomeDirectory();
+ if (path != null)
+ {
+ path = new File(path, ".subversion").getAbsolutePath();
+ }
+ }
+ return path;
+ }
+
+ /**
+ * @return The absolute path to the current user's home directory,
+ * or <code>null</code> if it cannot be determined.
+ */
+ private static String getUserHomeDirectory()
+ {
+ // ### LATER: Wrap the svn_user_get_homedir() API and try it
+ // ### first.
+ String path = System.getProperty("user.home");
+ return (path != null ? path : getEnv("HOME"));
+ }
+
+ /**
+ * @param envVar The name of the environment variable to retrieve.
+ * @return The named environment variable, or <code>null</code> if
+ * it cannot be retrieved.
+ */
+ private static final String getEnv(String envVar)
+ {
+ try
+ {
+ return System.getenv(envVar);
+ }
+ catch (Throwable jreComplaint)
+ {
+ // As an example, Sun JRE 1.4.2_12-b03 throws
+ // java.lang.Error, with the message "getenv no longer
+ // supported, use properties and -D instead: HOME".
+ return null;
+ }
+ }
+
+ /**
+ * @return Whether the current operating system is Windows.
+ */
+ private static final boolean isOSWindows()
+ {
+ String opSys = System.getProperty("os.name");
+ return (opSys.toLowerCase().indexOf("windows") >= 0);
+ }
+
+ /**
      * Build the native peer
      * @return the adress of the peer
      */

  • application/pgp-signature attachment: stored
Received on Wed Dec 20 22:54:12 2006

This is an archived mail posted to the Subversion Dev mailing list.