Author: j16sdiz
Date: 2009-03-24 02:07:31 +0000 (Tue, 24 Mar 2009)
New Revision: 26143

Modified:
   trunk/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
Log:
Create new store when config file load error

Currently, the node refuse to start if the config file
is truncated (zero-size). There are no way to recover
as the encryption key is stored in the file. This patch
create a new store whenever possible. (Close Bug 2923)

Modified: trunk/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java
===================================================================
--- trunk/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java      
2009-03-23 11:41:35 UTC (rev 26142)
+++ trunk/freenet/src/freenet/store/saltedhash/SaltedHashFreenetStore.java      
2009-03-24 02:07:31 UTC (rev 26143)
@@ -43,6 +43,7 @@
 import freenet.support.HTMLNode;
 import freenet.support.HexUtil;
 import freenet.support.Logger;
+import freenet.support.io.Closer;
 import freenet.support.io.FileUtil;
 import freenet.support.io.NativeThread;
 
@@ -849,8 +850,10 @@
                        writeConfigFile();
                        return true;
                } else {
+                       try {
                        // try to load
                        RandomAccessFile raf = new RandomAccessFile(configFile, 
"r");
+                               try {
                        byte[] salt = new byte[0x10];
                        raf.readFully(salt);
                        cipherManager = new CipherManager(salt);
@@ -875,8 +878,25 @@
                                flags |= FLAG_REBUILD_BLOOM;
                        }
 
-                       raf.close();
                        return false;
+                               } finally {
+                                       Closer.close(raf);
+                               }
+                       } catch (IOException e) {
+                               // corrupted? delete it and try again
+                               Logger.error(this, "config file corrupted, 
trying to create a new store: " + name, e);
+                               System.err.println("config file corrupted, 
trying to create a new store: " + name);
+                               if (configFile.exists() && configFile.delete()) 
{
+                                       File metaFile = new File(baseDir, name 
+ ".metadata");
+                                       metaFile.delete();
+                                       return loadConfigFile();
+                               }
+
+                               // last restore
+                               Logger.error(this, "can't delete config file, 
please delete the store manually: " + name, e);
+                               System.err.println( "can't delete config file, 
please delete the store manually: " + name);
+                               throw e;
+                       }
                }
        }
 

_______________________________________________
cvs mailing list
[email protected]
http://emu.freenetproject.org/cgi-bin/mailman/listinfo/cvs

Reply via email to