geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject svn commit: rev 55621 - in geronimo/trunk/modules/system/src: java/org/apache/geronimo/system/configuration test/org/apache/geronimo/system/configuration
Date Tue, 26 Oct 2004 17:13:57 GMT
Author: jboynes
Date: Tue Oct 26 10:13:57 2004
New Revision: 55621

Modified:
   geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java
   geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
Log:
something odd is going on with delete/rename on WinXP/JDK1.5; switching to a simple rename-to-backup/save-new
model

Modified: geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java
==============================================================================
--- geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java
(original)
+++ geronimo/trunk/modules/system/src/java/org/apache/geronimo/system/configuration/LocalConfigStore.java
Tue Oct 26 10:13:57 2004
@@ -58,6 +58,7 @@
  */
 public class LocalConfigStore implements ConfigurationStore, GBeanLifecycle {
     private static final String INDEX_NAME = "index.properties";
+    private static final String BACKUP_NAME = "index.backup";
     private final String objectName;
     private final URI root;
     private final ServerInfo serverInfo;
@@ -117,31 +118,26 @@
     }
 
     private void saveIndex() throws IOException {
+        // todo provide a backout mechanism
         File indexFile = new File(rootDir, INDEX_NAME);
-        File tmpFile = File.createTempFile("index", ".tmp", rootDir);
-        FileOutputStream fos = new FileOutputStream(tmpFile);
+        File backupFile = new File(rootDir, BACKUP_NAME);
+        if (backupFile.exists()) {
+            backupFile.delete();
+        }
+        indexFile.renameTo(backupFile);
+
+        FileOutputStream fos = new FileOutputStream(indexFile);
         try {
             BufferedOutputStream os = new BufferedOutputStream(fos);
             index.store(os, null);
             os.close();
             fos = null;
-            if ( indexFile.exists() && false == indexFile.delete() ) {
-                throw new IOException("Can not delete file " + indexFile);
-            }
-            if ( false == tmpFile.renameTo(indexFile) ) {
-                fos = new FileOutputStream(indexFile);
-                os = new BufferedOutputStream(fos);
-                index.store(os, null);
-                os.close();
-                if ( false == tmpFile.delete() ) {
-                    log.warn("Can not delete temporary file " + tmpFile);
-                }
-            }
         } catch (IOException e) {
             if (fos != null) {
                 fos.close();
             }
-            tmpFile.delete();
+            indexFile.delete();
+            backupFile.renameTo(indexFile);
             throw e;
         }
     }

Modified: geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
==============================================================================
--- geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
(original)
+++ geronimo/trunk/modules/system/src/test/org/apache/geronimo/system/configuration/LocalConfigStoreTest.java
Tue Oct 26 10:13:57 2004
@@ -50,6 +50,20 @@
         assertEquals(uri, config.getAttribute("ID"));
     }
 
+    public void testReInstall() throws Exception {
+        store.install(source);
+        store.install(source);
+        assertTrue(new File(root, "2/META-INF/config.ser").exists());
+        store.install(source);
+        assertTrue(new File(root, "3/META-INF/config.ser").exists());
+        store.install(source);
+        assertTrue(new File(root, "4/META-INF/config.ser").exists());
+        store.install(source);
+        assertTrue(new File(root, "5/META-INF/config.ser").exists());
+        store.install(source);
+        assertTrue(new File(root, "6/META-INF/config.ser").exists());
+    }
+
     protected void setUp() throws Exception {
         try {
             root = new File(System.getProperty("java.io.tmpdir") + "/config-store");

Mime
View raw message