On Sun, Jan 12, 2003 at 11:59:57PM +0000, Matthew Toseland wrote:
> Hmm. Which branch fred?
devel
> I'm reasonably sure I fixed this in the devel
> branch... 
The problem turned out to be a missing path separator, which made
/home/freenet/tmpbffile_* from /home/freenet/tmp and bffile_*.

> the solution was to put the node temp dir in the System
> parameter "java.io.tmpdir" or something similar...
Ah, that's a good idea.

tempDir handling is rather inconsistent across the codebase, how about
this patch (which also fixes the missing separator issue mentioned
above)? Making a seperate class just for this seems like overkill
though, is there some general utilities class it could go into?

-- 
Frank v Waveren                                      Fingerprint: 21A7 C7F3
fvw@[var.cx|stack.nl|chello.nl] ICQ#10074100            1FF3 47FF 545C CB53
Public key: hkp://wwwkeys.pgp.net/fvw at var.cx            7BD9 09C0 3AC1 6DF2
-------------- next part --------------
diff -urNbB freenet/client/http/TempBucketFactory.java 
freenet-fvw/client/http/TempBucketFactory.java
--- freenet/client/http/TempBucketFactory.java  Sat Jan 11 23:53:07 2003
+++ freenet-fvw/client/http/TempBucketFactory.java      Mon Jan 13 10:51:14 2003
@@ -28,14 +28,14 @@

   public TempBucketFactory(String temp) {
     tmpDir = temp;
-    if(tmpDir == null) tmpDir = System.getProperty("java.io.tmpdir");
+    if(tmpDir == null) tmpDir = TempDir.get();
 //     Core.logger.log(this, "Creating TempBucketFactory, tmpDir = "+
 //                 (tmpDir == null ? "(null)" : tmpDir),
 //                 new Exception("debug"), Core.logger.DEBUG);
   }

   public TempBucketFactory() {
-    this(System.getProperty("java.io.tmpdir"));
+    this(TempDir.get());
     if(Core.logger.shouldLog(Core.logger.DEBUG))
        Core.logger.log(this, "Creating TempBucketFactory, tmpDir = "+
                      (tmpDir == null ? "(null)" : tmpDir),
diff -urNbB freenet/node/Main.java freenet-fvw/node/Main.java
--- freenet/node/Main.java      Sat Jan 11 23:07:21 2003
+++ freenet-fvw/node/Main.java  Mon Jan 13 12:48:31 2003
@@ -893,7 +893,7 @@
            else d[x].delete();
        }

-       BucketFactory bf = new FileBucketFactory(tempDir);
+       BucketFactory bf = new FileBucketFactory(TempDir.get());

        Core.logger.log(Main.class, "loaded temp bucket factory", 
                        Logger.NORMAL);
diff -urNbB freenet/support/FileBucket.java freenet-fvw/support/FileBucket.java
--- freenet/support/FileBucket.java     Sat Jan 11 23:53:07 2003
+++ freenet-fvw/support/FileBucket.java Mon Jan 13 10:16:54 2003
@@ -31,6 +31,7 @@
         // (new Exception("get stack")).printStackTrace();
        fileRestartCounter = 0;
        length = file.length();
+       tempDir=TempDir.get();
     }

     /**
@@ -160,61 +161,5 @@
         tempDir = dirName;
     }

-    // determine the temp directory in one of several ways
-
-    static {
-       // Try the Java property (1.2 and above)
-       tempDir = System.getProperty("java.io.tmpdir");
-
-       // Deprecated calls removed.
-
-       // Try TEMP and TMP
-       //      if (tempDir == null) {
-       //          tempDir = System.getenv("TEMP");
-       //      }
-
-       //      if (tempDir == null) {
-       //          tempDir = System.getenv("TMP");
-       //      }
-
-       // make some semi-educated guesses based on OS.
-
-       if (tempDir == null) {
-           String os = System.getProperty("os.name");
-           if (os != null) {
-
-               String[] candidates = null; 
-
-               // XXX: Add more possible OSes here.
-               if (os.equalsIgnoreCase("Linux")) {
-                   String[] linuxCandidates = { "/tmp", "/var/tmp" };
-                   candidates = linuxCandidates;
-               } else if (os.equalsIgnoreCase("Windows")) {
-                   String[] windowsCandidates = { "C:\\TEMP", 
"C:\\WINDOWS\\TEMP" };
-                   candidates = windowsCandidates;
-               }
-
-               if (candidates != null) {
-                   for (int i = 0; i < candidates.length; i++) {
-                       File path = new File(candidates[i]);
-                       if (path.exists() &&
-                           path.isDirectory() &&
-                           path.canWrite())
-                       {
-                           tempDir = candidates[i];
-                           break;
-                       }
-                   }
-               }
-           }
-       }
-
-       // last resort -- use current working directory
-
-       if (tempDir == null) {
-           // This can be null -- but that's OK, null => cwd for File 
constructor, anyways.
-           tempDir = System.getProperty("user.dir");
-       }
-    }

 }
diff -urNbB freenet/support/FileBucketFactory.java 
freenet-fvw/support/FileBucketFactory.java
--- freenet/support/FileBucketFactory.java      Sat Jan  4 02:21:00 2003
+++ freenet-fvw/support/FileBucketFactory.java  Mon Jan 13 14:13:03 2003
@@ -10,14 +10,19 @@
     private Vector files = new Vector();

     // Must have trailing "/"
-    public String rootDir = "";
+    public String rootDir;

     public FileBucketFactory() {
-        
+       rootDir=TempDir.get();
     }

     public FileBucketFactory(String rootDir) {
+        if (rootDir==null || rootDir.length()==0) {
+           this.rootDir=TempDir.get();
+        } else {
         this.rootDir = rootDir;
+        }
+
     }

     public FileBucketFactory(File dir) {
diff -urNbB freenet/support/TempDir.java freenet-fvw/support/TempDir.java
--- freenet/support/TempDir.java        Thu Jan  1 01:00:00 1970
+++ freenet-fvw/support/TempDir.java    Mon Jan 13 14:12:56 2003
@@ -0,0 +1,87 @@
+package freenet.support;
+import java.io.*;
+
+/**
+ * TempDir tries very hard to find the proper temporary directory
+ * 
+ * @author oskar
+ **/
+
+// Thrown into a seperate class for reuse
+  
+public abstract class TempDir {
+
+   static String tempDir;
+
+   public static String get() {
+         return tempDir;
+      }
+   
+   static {
+         // Try the Java property (1.2 and above)
+         tempDir = System.getProperty("java.io.tmpdir");
+
+         // Deprecated calls removed.
+
+         // Try TEMP, TMPDIR and TMP
+         //  if (tempDir == null) {
+         //      tempDir = System.getenv("TEMP");
+         //  }
+         // 
+         //  if (tempDir == null) {
+         //      tempDir = System.getenv("TMPDIR");
+         //  }
+         // 
+         //  if (tempDir == null) {
+         //      tempDir = System.getenv("TMP");
+         //  }
+         // 
+         // make some semi-educated guesses based on OS.
+
+         if (tempDir == null) {
+            String os = System.getProperty("os.name");
+            if (os != null) {
+               
+               String[] candidates = null; 
+               
+               // XXX: Add more possible OSes here.
+               if (os.equalsIgnoreCase("Linux")) {
+                  String[] linuxCandidates = { "/tmp", "/var/tmp" };
+                  candidates = linuxCandidates;
+               } else if (os.equalsIgnoreCase("Windows")) {
+                  String[] windowsCandidates = { "C:\\TEMP", 
"C:\\WINDOWS\\TEMP" };
+                  candidates = windowsCandidates;
+               }
+               
+               if (candidates != null) {
+                  for (int i = 0; i < candidates.length; i++) {
+                     File path = new File(candidates[i]);
+                     if (path.exists() &&
+                         path.isDirectory() &&
+                         path.canWrite())
+                        {
+                           tempDir = candidates[i];
+                           break;
+                        }
+                  }
+               }
+            }
+         }
+      
+      // last resort -- use current working directory
+      if (tempDir == null) {
+         tempDir = System.getProperty("user.dir");
+      }
+
+      // Make sure there's a seperator at the end (if it's not the empty 
+      // string) so people can just concat their filename to it
+
+      if (tempDir.length()!=0 && 
+          !tempDir.endsWith(File.separator)) {
+         tempDir=tempDir.concat(File.separator);
+      }
+      
+   }
+}
+
+   

Reply via email to