Author: nextgens
Date: 2007-11-29 16:27:46 +0000 (Thu, 29 Nov 2007)
New Revision: 16091

Modified:
   trunk/freenet/src/freenet/node/Node.java
   trunk/freenet/src/freenet/node/PeerManager.java
   trunk/freenet/src/freenet/pluginmanager/PluginManager.java
Log:
same bugfix everywhere: move the new file over the existing one only if writing 
it succeeded!

Modified: trunk/freenet/src/freenet/node/Node.java
===================================================================
--- trunk/freenet/src/freenet/node/Node.java    2007-11-29 16:24:43 UTC (rev 
16090)
+++ trunk/freenet/src/freenet/node/Node.java    2007-11-29 16:27:46 UTC (rev 
16091)
@@ -485,13 +485,13 @@
                try {
                        fos = new FileOutputStream(backup);
                        fs.writeTo(fos);
+                       FileUtil.renameTo(backup, orig);
                 } catch (IOException ioe){
                         Logger.error(this, "IOE :"+ioe.getMessage(), ioe);
                         return;
                 } finally {
                         Closer.close(fos);
                }
-                FileUtil.renameTo(backup, orig);
        }

        private void initNodeFileSettings(RandomSource r) {

Modified: trunk/freenet/src/freenet/node/PeerManager.java
===================================================================
--- trunk/freenet/src/freenet/node/PeerManager.java     2007-11-29 16:24:43 UTC 
(rev 16090)
+++ trunk/freenet/src/freenet/node/PeerManager.java     2007-11-29 16:27:46 UTC 
(rev 16091)
@@ -880,6 +880,8 @@
                boolean succeeded = writePeers(bw, peers);
                 bw.close(); bw = null;
                 if(!succeeded) return;
+               File fnam = new File(filename);
+               FileUtil.renameTo(new File(f), fnam);
             } catch (IOException e) {
                try {
                        fos.close();
@@ -892,8 +894,6 @@
                    Closer.close(bw);
                    Closer.close(fos);
            }
-            File fnam = new File(filename);
-            FileUtil.renameTo(new File(f), fnam);
         }
     }


Modified: trunk/freenet/src/freenet/pluginmanager/PluginManager.java
===================================================================
--- trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2007-11-29 
16:24:43 UTC (rev 16090)
+++ trunk/freenet/src/freenet/pluginmanager/PluginManager.java  2007-11-29 
16:27:46 UTC (rev 16091)
@@ -515,6 +515,11 @@
                                while ((read = pluginInputStream.read(buffer)) 
!= -1) {
                                        pluginOutputStream.write(buffer, 0, 
read);
                                }
+                                                       
+                               if(!FileUtil.renameTo(tempPluginFile, 
pluginFile)) {
+                                       Logger.error(this, "could not rename 
temp file to plugin file");
+                                       throw new 
PluginNotFoundException("could not rename temp file to plugin file");
+                               }
                        } catch (IOException ioe1) {
                                Logger.error(this, "could not load plugin", 
ioe1);
                                if (tempPluginFile != null) {
@@ -525,11 +530,6 @@
                                Closer.close(pluginOutputStream);
                                Closer.close(pluginInputStream);
                        }
-                        
-                       if (!FileUtil.renameTo(tempPluginFile, pluginFile)) {
-                               Logger.error(this, "could not rename temp file 
to plugin file");
-                               throw new PluginNotFoundException("could not 
rename temp file to plugin file");
-                       }
                }

                /* now get the manifest file. */


Reply via email to