Author: toad
Date: 2007-03-21 02:14:52 +0000 (Wed, 21 Mar 2007)
New Revision: 12246

Modified:
   trunk/freenet/src/freenet/support/io/FileBucket.java
   trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java
Log:
Fix recently introduced buckets bug: Use absolute filenames.

Modified: trunk/freenet/src/freenet/support/io/FileBucket.java
===================================================================
--- trunk/freenet/src/freenet/support/io/FileBucket.java        2007-03-21 
01:42:32 UTC (rev 12245)
+++ trunk/freenet/src/freenet/support/io/FileBucket.java        2007-03-21 
02:14:52 UTC (rev 12246)
@@ -23,7 +23,7 @@
  */
 public class FileBucket implements Bucket, SerializableToFieldSetBucket {

-       protected File file;
+       protected final File file;
        protected boolean readOnly;
        protected boolean deleteOnFinalize;
        protected boolean deleteOnFree;
@@ -163,6 +163,8 @@
                        File tempfile, String s, long restartCount)
                        throws FileNotFoundException {
                        super(tempfile, false);
+                       if(Logger.shouldLog(Logger.MINOR, this))
+                               Logger.minor(this, "Writing to "+tempfile+" for 
"+file);
                        this.tempfile = tempfile;
                        resetLength();
                        this.restartCount = restartCount;
@@ -200,20 +202,31 @@
                }

                public void close() throws IOException {
+                       boolean logMINOR = Logger.shouldLog(Logger.MINOR, this);
+                       if(logMINOR)
+                               Logger.minor(this, "Closing "+FileBucket.this);
                        try {
                                super.close();
                        } catch (IOException e) {
+                               if(logMINOR)
+                                       Logger.minor(this, "Failed closing 
"+FileBucket.this+" : "+e, e);
                                if(createFileOnly) tempfile.delete();
                                throw e;
                        }
                        if(createFileOnly) {
                                if(file.exists()) {
+                                       if(logMINOR)
+                                               Logger.minor(this, "File exists 
creating file for "+this);
                                        tempfile.delete();
                                        throw new FileExistsException(file);
                                }
                                if(!tempfile.renameTo(file)) {
+                                       if(logMINOR)
+                                               Logger.minor(this, "Cannot 
rename file for "+this);
                                        if(file.exists()) throw new 
FileExistsException(file);
                                        tempfile.delete();
+                                       if(logMINOR)
+                                               Logger.minor(this, "Deleted, 
cannot rename file for "+this);
                                        throw new IOException("Cannot rename 
file");
                                }
                        }
@@ -231,9 +244,11 @@
        }

        public synchronized InputStream getInputStream() throws IOException {
-               return file.exists()
-                       ? (InputStream) new FileBucketInputStream(file)
-                       : (InputStream) new NullInputStream();
+               if(!file.exists()) {
+                       Logger.normal(this, "File does not exist: "+file+" for 
"+this);
+                       return new NullInputStream();
+               } else 
+                       return new FileBucketInputStream(file);
        }

        /**

Modified: trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java
===================================================================
--- trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java       
2007-03-21 01:42:32 UTC (rev 12245)
+++ trunk/freenet/src/freenet/support/io/PersistentTempBucketFactory.java       
2007-03-21 02:14:52 UTC (rev 12246)
@@ -41,7 +41,7 @@
        private final LinkedList bucketsToFree;

        public PersistentTempBucketFactory(File dir, String prefix, 
RandomSource rand) throws IOException {
-               this.dir = dir;
+               this.dir = dir.getAbsoluteFile();
                this.rand = rand;
                this.fg = new FilenameGenerator(rand, false, dir, prefix);
                if(!dir.exists()) {
@@ -65,7 +65,7 @@
                                        Logger.minor(this, "Ignoring "+name);
                                        continue;
                                }
-                               originalFiles.add(f);
+                               originalFiles.add(f.getAbsoluteFile());
                        }
                }
                bucketsToFree = new LinkedList();
@@ -73,7 +73,8 @@

        public void register(File file) {
                synchronized(this) {
-                       originalFiles.remove(file);
+                       if(!originalFiles.remove(file.getAbsoluteFile()))
+                               Logger.error(this, "Preserving "+file+" but it 
wasn't found!");
                }
        }



Reply via email to