Author: toad
Date: 2008-06-25 15:16:33 +0000 (Wed, 25 Jun 2008)
New Revision: 20687

Modified:
   branches/db4o/freenet/src/freenet/node/NodeClientCore.java
   
branches/db4o/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java
Log:
Persist the PersistentEncryptedTempBucketFactory to avoid leaking space and 
avoid activation problems

Modified: branches/db4o/freenet/src/freenet/node/NodeClientCore.java
===================================================================
--- branches/db4o/freenet/src/freenet/node/NodeClientCore.java  2008-06-25 
15:15:43 UTC (rev 20686)
+++ branches/db4o/freenet/src/freenet/node/NodeClientCore.java  2008-06-25 
15:16:33 UTC (rev 20687)
@@ -219,7 +219,7 @@
                        String prefix = "freenet-temp-";
                        persistentTempBucketFactory = 
PersistentTempBucketFactory.load(dir, prefix, random, node.fastWeakRandom, 
container, node.nodeDBHandle);
                        persistentTempBucketFactory.init(dir, prefix, random, 
node.fastWeakRandom);
-                       persistentEncryptedTempBucketFactory = new 
PersistentEncryptedTempBucketFactory(persistentTempBucketFactory);
+                       persistentEncryptedTempBucketFactory = 
PersistentEncryptedTempBucketFactory.load(persistentTempBucketFactory, 
container);
                } catch (IOException e2) {
                        String msg = "Could not find or create persistent 
temporary directory";
                        throw new 
NodeInitException(NodeInitException.EXIT_BAD_TEMP_DIR, msg);

Modified: 
branches/db4o/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java
===================================================================
--- 
branches/db4o/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java
      2008-06-25 15:15:43 UTC (rev 20686)
+++ 
branches/db4o/freenet/src/freenet/support/io/PersistentEncryptedTempBucketFactory.java
      2008-06-25 15:16:33 UTC (rev 20687)
@@ -5,6 +5,10 @@

 import java.io.IOException;

+import com.db4o.ObjectContainer;
+import com.db4o.ObjectSet;
+import com.db4o.query.Predicate;
+
 import freenet.support.api.Bucket;
 import freenet.support.api.BucketFactory;

@@ -20,4 +24,17 @@
        public Bucket makeBucket(long size) throws IOException {
                return bf.makeEncryptedBucket();
        }
+
+       public static PersistentEncryptedTempBucketFactory load(final 
PersistentTempBucketFactory persistentTempBucketFactory, ObjectContainer 
container) {
+               ObjectSet results = container.query(new Predicate() {
+                       public boolean 
match(PersistentEncryptedTempBucketFactory bf) {
+                               return bf.bf == persistentTempBucketFactory;
+                       }
+               });
+               if(results.hasNext()) {
+                       return (PersistentEncryptedTempBucketFactory) 
results.next();
+               } else {
+                       return new 
PersistentEncryptedTempBucketFactory(persistentTempBucketFactory);
+               }
+       }
 }


Reply via email to