Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-08-05 14:22:15 +0000
committerThomas Watson2011-08-05 14:22:15 +0000
commitb3075dd5c8ce66d53143bb6faab4866a4aedff2a (patch)
treedc4330dce164ae26f667830a0c0ac14dc19275f6
parentbe645b485ea5d3de1cb3a2c41b5704f2edcc5665 (diff)
downloadrt.equinox.framework-b3075dd5c8ce66d53143bb6faab4866a4aedff2a.tar.gz
rt.equinox.framework-b3075dd5c8ce66d53143bb6faab4866a4aedff2a.tar.xz
rt.equinox.framework-b3075dd5c8ce66d53143bb6faab4866a4aedff2a.zip
Bug 353879 - Add cleanupOnSave optionR37x_v20110808-1106
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/FileManagerTests.java100
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java5
2 files changed, 96 insertions, 9 deletions
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/FileManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/FileManagerTests.java
index baf430a83..a97d55f5f 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/FileManagerTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/FileManagerTests.java
@@ -16,6 +16,7 @@ import junit.framework.TestSuite;
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.storagemanager.StorageManager;
import org.eclipse.osgi.tests.OSGiTest;
+import org.osgi.framework.Constants;
public class FileManagerTests extends OSGiTest {
StorageManager manager1;
@@ -376,10 +377,11 @@ public class FileManagerTests extends OSGiTest {
*/
public void testMultipleFileManagers() {
// This test relies on a file lock to fail if the same process already
- // holds a file lock. This is true on Win32 but not on Linux. So run
- // this test for windows only.
- if (!"win32".equalsIgnoreCase(System.getProperty("osgi.os")))
- // this is a Windows-only test
+ // holds a file lock. This is true on Win32 but not on Linux/Mac unless using Java 6.
+ // So run this test for windows only.
+ String ee = System.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
+ if (!"win32".equalsIgnoreCase(System.getProperty("osgi.os")) && ee.indexOf("JavaSE-1.6") == -1)
+ // this is a Windows-only test or JavaSE-1.6 or higher test
return;
String fileName = "testMultipleFileManagers.txt";
File file1 = new File(base, fileName + ".1");
@@ -497,8 +499,8 @@ public class FileManagerTests extends OSGiTest {
}
}
- public void testCleanup() {
- String fileName = "testCleanup.txt";
+ public void testCleanupOnOpen() {
+ String fileName = getName() + ".txt";
File file1 = new File(base, fileName + ".1");
File file2 = new File(base, fileName + ".2");
File file3 = new File(base, fileName + ".3");
@@ -522,7 +524,7 @@ public class FileManagerTests extends OSGiTest {
writeToFile(tmpFile, "File exists #2");
manager1.update(new String[] {fileName}, new String[] {tmpFile.getName()});
// sanity check
- assertFalse(file1.toString(), file1.exists());
+ assertTrue(file1.toString(), file1.exists());
assertTrue(file2.toString(), file2.exists());
assertFalse(file3.toString(), file3.exists());
@@ -531,6 +533,39 @@ public class FileManagerTests extends OSGiTest {
writeToFile(tmpFile, "File exists #3");
manager1.update(new String[] {fileName}, new String[] {tmpFile.getName()});
// sanity check
+ assertTrue(file1.toString(), file1.exists());
+ assertTrue(file2.toString(), file2.exists());
+ assertTrue(file3.toString(), file3.exists());
+
+ // This test relies on a file lock to fail if the same process already
+ // holds a file lock. This is true on Win32 but not on Linux/Mac unless using Java 6.
+ // So run this test for windows only or Java 6 or higher.
+ String ee = System.getProperty(Constants.FRAMEWORK_EXECUTIONENVIRONMENT);
+ if ("win32".equalsIgnoreCase(System.getProperty("osgi.os")) || ee.indexOf("JavaSE-1.6") != -1) {
+ // this is a Windows-only test or JavaSE-1.6 or higher test
+ // Check to see that a new manager does not delete on open/close while manager1 is open
+ manager2 = new StorageManager(base, null);
+ manager2.open(true);
+ manager2.close();
+ // sanity check
+ assertTrue(file1.toString(), file1.exists());
+ assertTrue(file2.toString(), file2.exists());
+ assertTrue(file3.toString(), file3.exists());
+ }
+
+ manager1.close(); // force a cleanup
+ // sanity check
+ assertFalse(file1.toString(), file1.exists());
+ assertFalse(file2.toString(), file2.exists());
+ assertTrue(file3.toString(), file3.exists());
+
+ // recreate file1 and file2 to test cleanup on open
+ writeToFile(file1, "File exists #1");
+ writeToFile(file2, "File exists #2");
+ assertTrue(file1.toString(), file1.exists());
+ assertTrue(file2.toString(), file2.exists());
+ manager1.open(true);
+ // sanity check
assertFalse(file1.toString(), file1.exists());
assertFalse(file2.toString(), file2.exists());
assertTrue(file3.toString(), file3.exists());
@@ -547,4 +582,55 @@ public class FileManagerTests extends OSGiTest {
System.setProperty("osgi.embedded.cleanupOnOpen", "false");
}
}
+
+ public void testCleanupOnSave() {
+ String fileName = getName() + ".txt";
+ File file1 = new File(base, fileName + ".1");
+ File file2 = new File(base, fileName + ".2");
+ File file3 = new File(base, fileName + ".3");
+ System.setProperty("osgi.embedded.cleanupOnSave", "true");
+ // create a permanent file
+ try {
+ manager1 = new StorageManager(base, null);
+ manager1.open(true);
+ manager1.add(fileName);
+ // create version (1)
+ File tmpFile = manager1.createTempFile(fileName);
+ writeToFile(tmpFile, "File exists #1");
+ manager1.update(new String[] {fileName}, new String[] {tmpFile.getName()});
+ // sanity check
+ assertTrue(file1.toString(), file1.exists());
+ assertFalse(file2.toString(), file2.exists());
+ assertFalse(file3.toString(), file3.exists());
+
+ // do it again, now version (2)
+ tmpFile = manager1.createTempFile(fileName);
+ writeToFile(tmpFile, "File exists #2");
+ manager1.update(new String[] {fileName}, new String[] {tmpFile.getName()});
+ // sanity check
+ assertFalse(file1.toString(), file1.exists());
+ assertTrue(file2.toString(), file2.exists());
+ assertFalse(file3.toString(), file3.exists());
+
+ // do it again, now version (3)
+ tmpFile = manager1.createTempFile(fileName);
+ writeToFile(tmpFile, "File exists #3");
+ manager1.update(new String[] {fileName}, new String[] {tmpFile.getName()});
+ // sanity check
+ assertFalse(file1.toString(), file1.exists());
+ assertFalse(file2.toString(), file2.exists());
+ assertTrue(file3.toString(), file3.exists());
+
+ manager1.close(); // force a cleanup
+ manager1 = null;
+ // sanity check
+ assertFalse(file1.toString(), file1.exists());
+ assertFalse(file2.toString(), file2.exists());
+ assertTrue(file3.toString(), file3.exists());
+ } catch (IOException e) {
+ fail("unexpected exception", e);
+ } finally {
+ System.setProperty("osgi.embedded.cleanupOnSave", "false");
+ }
+ }
}
diff --git a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java
index 532014b58..25823bcb4 100644
--- a/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java
+++ b/bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java
@@ -95,6 +95,7 @@ public final class StorageManager {
private final boolean useReliableFiles = Boolean.valueOf(secure.getProperty("osgi.useReliableFiles")).booleanValue(); //$NON-NLS-1$
private final boolean tempCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanTempFiles")).booleanValue(); //$NON-NLS-1$
private final boolean openCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanupOnOpen")).booleanValue(); //$NON-NLS-1$
+ private final boolean saveCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanupOnSave")).booleanValue(); //$NON-NLS-1$
private class Entry {
int readId;
@@ -555,7 +556,7 @@ public final class StorageManager {
fileStream.abort();
}
// bug 259981 we should clean up
- if (openCleanup) {
+ if (saveCleanup) {
try {
cleanup(false);
} catch (IOException ex) {
@@ -606,7 +607,7 @@ public final class StorageManager {
String[] files = managerRoot.list();
if (files != null) {
for (int i = 0; i < files.length; i++) {
- if (files[i].endsWith(".instance") && instanceFile != null && !files[i].equalsIgnoreCase(instanceFile.getName())) { //$NON-NLS-1$
+ if (files[i].endsWith(".instance") && (instanceFile == null || !files[i].equalsIgnoreCase(instanceFile.getName()))) { //$NON-NLS-1$
Locker tmpLocker = BasicLocation.createLocker(new File(managerRoot, files[i]), lockMode);
if (tmpLocker.lock()) {
//If I can lock it is a file that has been left behind by a crash

Back to the top