directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From seelm...@apache.org
Subject svn commit: r548133 - /directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
Date Sun, 17 Jun 2007 22:48:28 GMT
Author: seelmann
Date: Sun Jun 17 15:48:27 2007
New Revision: 548133

URL: http://svn.apache.org/viewvc?view=rev&rev=548133
Log:
DIRSTUDIO-101: Write configuration into a temporary file first, then rename it to the real
configuration file. This should reduce the probability of loosing configuration.

Modified:
    directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java

Modified: directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
URL: http://svn.apache.org/viewvc/directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java?view=diff&rev=548133&r1=548132&r2=548133
==============================================================================
--- directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
(original)
+++ directory/studio/trunk/studio-ldapbrowser-core/src/main/java/org/apache/directory/studio/ldapbrowser/core/ConnectionManager.java
Sun Jun 17 15:48:27 2007
@@ -562,20 +562,26 @@
         XMLEncoder encoder = null;
         try
         {
+            // to avoid a corrupt file, save object to a temp file first 
+            String tempFilename = filename + "-temp";
             Thread.currentThread().setContextClassLoader( getClass().getClassLoader() );
-            encoder = new XMLEncoder( new BufferedOutputStream( new FileOutputStream( filename
) ) );
-
+            encoder = new XMLEncoder( new BufferedOutputStream( new FileOutputStream( tempFilename
) ) );
             encoder.setExceptionListener( new ExceptionListener()
             {
-
                 public void exceptionThrown( Exception e )
                 {
                     e.printStackTrace();
                 }
-
             } );
-
             encoder.writeObject( object );
+            
+            // move temp file to good file
+            File file = new File( filename );
+            File tempFile = new File( tempFilename );
+            if( file.exists() ) {
+                file.delete();
+            }
+            tempFile.renameTo( file );
         }
         catch ( Exception e )
         {



Mime
View raw message