tmf: Bug 479675: Fix for index not being properly deleted on Windows
authorMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Thu, 19 Nov 2015 23:44:35 +0000 (18:44 -0500)
committerMarc-Andre Laperle <marc-andre.laperle@ericsson.com>
Fri, 11 Dec 2015 18:47:53 +0000 (13:47 -0500)
Change-Id: Idc97913cf34658452fef95f6e3ba502a57fc13ab
Signed-off-by: Marc-Andre Laperle <marc-andre.laperle@ericsson.com>
Reviewed-on: https://git.eclipse.org/r/60858
Reviewed-by: Patrick Tasse <patrick.tasse@gmail.com>
Tested-by: Patrick Tasse <patrick.tasse@gmail.com>
Reviewed-by: Hudson CI
tmf/org.eclipse.tracecompass.tmf.core.tests/src/org/eclipse/tracecompass/tmf/core/tests/trace/indexer/AbstractCheckpointCollectionTest.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/indexer/AbstractFileCheckpointCollection.java
tmf/org.eclipse.tracecompass.tmf.core/src/org/eclipse/tracecompass/internal/tmf/core/trace/indexer/BTree.java

index 5f0a5d1529a4f845723e8de0c8f1ce6392b62c0a..2fd655eecfeb4a8fd75253c34ff2758a1c8d2f19 100644 (file)
@@ -221,6 +221,32 @@ public abstract class AbstractCheckpointCollectionTest {
         assertTrue(fCheckpointCollection.isCreatedFromScratch());
     }
 
+    /**
+     * Test version change
+     *
+     * @throws IOException
+     *             can throw this
+     */
+    @Test
+    public void testDeleteWhenInvalidBug479675() throws IOException {
+        insertAlot();
+        try (RandomAccessFile f = new RandomAccessFile(fFile, "rw");) {
+            f.writeInt(-1);
+        }
+
+        fCheckpointCollection = createCollection();
+        if (isPersistableCollection()) {
+            ICheckpointCollection old = fCheckpointCollection;
+            try {
+                fCheckpointCollection = createCollection();
+                assertEquals(0, fCheckpointCollection.size());
+            } finally {
+                old.dispose();
+            }
+        }
+        assertTrue(fCheckpointCollection.isCreatedFromScratch());
+    }
+
     /**
      * Test a single insertion
      */
index 8378f821ca29f9c105fbc1bb611186966baaefa0..1f4878df180c8dc5f046d14d566a96b2f72720f0 100644 (file)
@@ -197,8 +197,7 @@ public abstract class AbstractFileCheckpointCollection implements ICheckpointCol
         if (!isCreatedFromScratch()) {
             header = tryRestore();
             if (header == null) {
-                fFile.delete();
-                dispose();
+                delete();
             }
         }
 
@@ -442,7 +441,7 @@ public abstract class AbstractFileCheckpointCollection implements ICheckpointCol
      */
     @Override
     public void delete() {
-        dispose();
+        dispose(true);
         if (fFile.exists()) {
             fFile.delete();
         }
@@ -453,14 +452,20 @@ public abstract class AbstractFileCheckpointCollection implements ICheckpointCol
      */
     @Override
     public void dispose() {
+        dispose(false);
+    }
+
+    private void dispose(boolean deleting) {
         try {
             if (fRandomAccessFile != null) {
-                if (fHeader != null) {
-                    fHeader.serialize(fRandomAccessFile);
-                }
+                if (!deleting) {
+                    if (fHeader != null) {
+                        fHeader.serialize(fRandomAccessFile);
+                    }
 
-                fRandomAccessFile.seek(0);
-                fRandomAccessFile.writeInt(getVersion());
+                    fRandomAccessFile.seek(0);
+                    fRandomAccessFile.writeInt(getVersion());
+                }
 
                 fRandomAccessFile.close();
             }
index 682faca6e74391c432c01384ee4d29cc8a8f2998..32ae555876955af9c290330f747f258d866f5b6e 100644 (file)
@@ -365,7 +365,7 @@ public class BTree extends AbstractFileCheckpointCollection {
 
     @Override
     public void dispose() {
-        if (fNodeCache != null) {
+        if (fNodeCache != null && getRandomAccessFile() != null) {
             fNodeCache.serialize();
         }
 
This page took 0.042467 seconds and 5 git commands to generate.