Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorThomas Watson2011-08-04 21:39:46 +0000
committerThomas Watson2011-08-04 21:39:46 +0000
commitbe645b485ea5d3de1cb3a2c41b5704f2edcc5665 (patch)
tree2f3095be710d1d39b64edb5dfde079340e25b3fc
parent098ec2fe0757231dee3d7ff919cf6e66e00df026 (diff)
downloadrt.equinox.framework-be645b485ea5d3de1cb3a2c41b5704f2edcc5665.tar.gz
rt.equinox.framework-be645b485ea5d3de1cb3a2c41b5704f2edcc5665.tar.xz
rt.equinox.framework-be645b485ea5d3de1cb3a2c41b5704f2edcc5665.zip
Bug 353880 - Numerous outdated bundledata/configuration files created in
equinox stack
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/FileManagerTests.java181
-rw-r--r--bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/StreamManagerTests.java131
-rw-r--r--bundles/org.eclipse.osgi/supplement/src/org/eclipse/osgi/storagemanager/StorageManager.java32
3 files changed, 199 insertions, 145 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 838bd6943..baf430a83 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,7 +11,6 @@
package org.eclipse.osgi.tests.services.datalocation;
import java.io.*;
-
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.Platform;
@@ -54,15 +53,14 @@ public class FileManagerTests extends OSGiTest {
if (file.isDirectory()) {
File[] list = file.listFiles();
if (list != null) {
- for (int idx=0; idx<list.length; idx++) {
+ for (int idx = 0; idx < list.length; idx++) {
rm(list[idx]);
}
}
}
file.delete();
}
-
-
+
/**
* Open a filemanager in readonly and ensure files are
* not created.
@@ -76,7 +74,7 @@ public class FileManagerTests extends OSGiTest {
manager1 = new StorageManager(testDir, null, true);
try {
manager1.open(true);
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
}
files = testDir.list();
@@ -84,21 +82,21 @@ public class FileManagerTests extends OSGiTest {
try {
manager1.add(fileName);
fail("add succedded");
- } catch(IOException e) {
+ } catch (IOException e) {
//good
}
-
+
try {
manager1.lookup(fileName, true);
fail("lookup succedded");
- } catch(IOException e) {
+ } catch (IOException e) {
//good
}
-
+
try {
manager1.createTempFile(fileName);
fail("create temp file succedded");
- } catch(IOException e) {
+ } catch (IOException e) {
//good
}
files = testDir.list();
@@ -116,12 +114,11 @@ public class FileManagerTests extends OSGiTest {
manager2.update(new String[] {fileName}, new String[] {tmpFile.getName()});
manager2.close();
manager2 = null;
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
- }
+ }
}
-
-
+
void writeToFile(File file, String str) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
try {
@@ -133,7 +130,6 @@ public class FileManagerTests extends OSGiTest {
}
}
-
private String getInputStreamContents(InputStream is) throws IOException {
StringBuffer sb = new StringBuffer();
byte[] data = new byte[64];
@@ -141,14 +137,13 @@ public class FileManagerTests extends OSGiTest {
try {
while ((len = is.read(data)) != -1) {
sb.append(new String(data, 0, len));
- }
+ }
} finally {
is.close();
}
return sb.toString();
}
-
-
+
/**
* This tests a FM update where the a specific file is managed with a
* revision number of (n) and an update is requested while there already
@@ -161,10 +156,10 @@ public class FileManagerTests extends OSGiTest {
manager1 = new StorageManager(base, null);
try {
manager1.open(false);
- File file1 = new File(base, testFile+".1");
- File file2 = new File(base, testFile+".2");
- File file3 = new File(base, testFile+".3");
- File file4 = new File(base, testFile+".4");
+ File file1 = new File(base, testFile + ".1");
+ File file2 = new File(base, testFile + ".2");
+ File file3 = new File(base, testFile + ".3");
+ File file4 = new File(base, testFile + ".4");
if (file1.exists() || file2.exists() || file3.exists() || file4.exists()) {
fail("Test files already exists.");
return;
@@ -178,7 +173,7 @@ public class FileManagerTests extends OSGiTest {
fail("Failed to create a single test file");
return;
}
-
+
// create file version (2) outside filemanager
writeToFile(file2, "file2 exists");
@@ -190,7 +185,7 @@ public class FileManagerTests extends OSGiTest {
fail("Failed to skip existing filemanager file.");
return;
}
-
+
// open a new manager, ensure a lookup results in file version (3)
manager2 = new StorageManager(base, null);
manager2.open(true);
@@ -203,18 +198,17 @@ public class FileManagerTests extends OSGiTest {
assertTrue(file.exists());
FileInputStream fis = new FileInputStream(file);
assertEquals(getInputStreamContents(fis), "file 3 contents");
-
+
manager2.close();
- manager2=null;
-
+ manager2 = null;
+
manager1.close();
- manager1=null;
- } catch(IOException e) {
+ manager1 = null;
+ } catch (IOException e) {
fail("unexpected exception", e);
}
}
-
/**
* This tests that FM apis throw exceptions if FM has not yet been opened
* or if FM has been closed.
@@ -231,17 +225,17 @@ public class FileManagerTests extends OSGiTest {
this.writeToFile(tmpFile, "File exists");
manager1.update(new String[] {permanentFile}, new String[] {tmpFile.getName()});
manager1.add(scratchFile);
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
}
-
+
// create a new manager, and try making calls
manager2 = new StorageManager(base, null);
checkOpen(false, permanentFile, scratchFile);
// open the manager, try again
try {
manager2.open(true);
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
}
checkOpen(true, permanentFile, scratchFile);
@@ -249,7 +243,7 @@ public class FileManagerTests extends OSGiTest {
manager2.close();
checkOpen(false, permanentFile, scratchFile);
manager2 = null;
-
+
manager1.close();
manager1 = null;
}
@@ -261,7 +255,7 @@ public class FileManagerTests extends OSGiTest {
if (!open)
fail("add did not fail.");
manager2.remove("failFile");
- } catch(IOException e) {
+ } catch (IOException e) {
if (open)
fail("unexpected exception", e);
}
@@ -271,7 +265,7 @@ public class FileManagerTests extends OSGiTest {
manager2.lookup(permanentFile, false);
if (!open)
fail("lookup did not fail.");
- } catch(IOException e) {
+ } catch (IOException e) {
if (open)
fail("unexpected exception", e);
}
@@ -283,13 +277,13 @@ public class FileManagerTests extends OSGiTest {
} catch (IOException e) {
fail("unexpected exception", e);
tmpFile = null;
- }
+ }
if (tmpFile != null) {
try {
manager2.update(new String[] {permanentFile}, new String[] {tmpFile.getName()});
if (!open)
fail("update did not fail.");
- } catch(IOException e) {
+ } catch (IOException e) {
if (open)
fail("unexpected exception", e);
}
@@ -299,15 +293,15 @@ public class FileManagerTests extends OSGiTest {
manager2.remove(scratchFile);
if (!open)
fail("remove did not fail");
- else // add the file back if expected to complete
+ else
+ // add the file back if expected to complete
manager2.add(scratchFile);
- } catch(IOException e) {
+ } catch (IOException e) {
if (open)
fail("unexpected exception", e);
}
}
-
-
+
/**
* This tests FM remove() then add(). On a remove(), the file can not be deleted as it may
* be in use by another FM. Then add() the file back and see if the version number written to
@@ -319,9 +313,9 @@ public class FileManagerTests extends OSGiTest {
*/
public void testRemoveThenAdd() {
String fileName = "testRemoveThenAdd.txt";
- File file1 = new File(base, fileName+".1");
- File file2 = new File(base, fileName+".2");
- File file3 = new File(base, fileName+".3");
+ File file1 = new File(base, fileName + ".1");
+ File file2 = new File(base, fileName + ".2");
+ File file3 = new File(base, fileName + ".3");
manager1 = new StorageManager(base, null);
// create a permanent file
try {
@@ -340,7 +334,7 @@ public class FileManagerTests extends OSGiTest {
// sanity check
if (file1.exists() || !file2.exists() || file3.exists())
fail("Failed creating a file revision");
-
+
manager2 = new StorageManager(base, null);
manager2.open(true);
manager2.remove(fileName);
@@ -359,7 +353,7 @@ public class FileManagerTests extends OSGiTest {
assertNotNull(testFile);
assertTrue(testFile.getName().endsWith(".3"));
assertTrue(file3.exists());
-
+
// open a new manager, ensure that the database was updated
// by checking version is also #3
manager1 = new StorageManager(base, null);
@@ -367,16 +361,16 @@ public class FileManagerTests extends OSGiTest {
testFile = manager1.lookup(fileName, false);
assertNotNull(testFile);
assertTrue(testFile.getName().endsWith(".3"));
-
+
manager1.close();
manager1 = null;
manager2.close();
manager2 = null;
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
}
}
-
+
/**
* Test multiple FM do not cleanup any old files as they may be in use.
*/
@@ -388,8 +382,8 @@ public class FileManagerTests extends OSGiTest {
// this is a Windows-only test
return;
String fileName = "testMultipleFileManagers.txt";
- File file1 = new File(base, fileName+".1");
- File file2 = new File(base, fileName+".2");
+ File file1 = new File(base, fileName + ".1");
+ File file2 = new File(base, fileName + ".2");
manager1 = new StorageManager(base, null);
try {
manager1.open(true);
@@ -398,13 +392,13 @@ public class FileManagerTests extends OSGiTest {
file = manager1.createTempFile(fileName);
writeToFile(file, "test contents #1");
manager1.update(new String[] {fileName}, new String[] {file.getName()});
-
+
// ensure file is version #1
file = manager1.lookup(fileName, false);
assertNotNull(file);
assertTrue(file.getName().endsWith(".1"));
assertTrue(file1.exists());
-
+
//new fileMangager using version #1
manager2 = new StorageManager(base, null);
manager2.open(true);
@@ -413,7 +407,7 @@ public class FileManagerTests extends OSGiTest {
assertNotNull(file);
assertTrue(file.getName().endsWith(".1"));
assertTrue(file1.exists() && !file2.exists());
-
+
// back to manager #1, update file again, close
file = manager1.createTempFile(fileName);
writeToFile(file, "test contents #2");
@@ -426,7 +420,7 @@ public class FileManagerTests extends OSGiTest {
// both files better still exists
assertTrue(file1.exists());
assertTrue(file2.exists());
-
+
// manager #2
// sanity check
file = manager2.lookup(fileName, false);
@@ -437,20 +431,20 @@ public class FileManagerTests extends OSGiTest {
manager2 = null;
assertTrue(!file1.exists());
assertTrue(file2.exists());
-
+
// new manager1, does it get version 1?
manager1 = new StorageManager(base, null);
manager1.open(true);
file = manager1.lookup(fileName, false);
assertNotNull(file);
assertTrue(file.getName().endsWith(".2"));
- manager1.close();
+ manager1.close();
manager1 = null;
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
}
}
-
+
/**
* This test will verify that a FM will fail if a lock is held
*/
@@ -460,11 +454,11 @@ public class FileManagerTests extends OSGiTest {
// this is a Windows-only test
return;
String fileName = "testJavaIOLocking";
- File lockFile = new File(new File(base,".manager"),".fileTableLock");
+ File lockFile = new File(new File(base, ".manager"), ".fileTableLock");
lockFile.getParentFile().mkdirs();
try {
new FileOutputStream(lockFile).close();
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
}
assertTrue(lockFile.exists());
@@ -476,30 +470,81 @@ public class FileManagerTests extends OSGiTest {
try {
manager1.open(true); // wait for lock
fail("open with lock succedded");
- } catch(IOException e) {
+ } catch (IOException e) {
//good
}
-
+
manager1.open(false); // don't wait, should work
try {
manager1.add(fileName);
fail("add succedded");
- } catch(IOException e) {
+ } catch (IOException e) {
//good
}
//sanity check, file should not be managed
assertNull(manager1.lookup(fileName, false));
manager1.close();
manager1 = null;
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
} finally {
try {
if (fos != null)
fos.close();
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexpected exception", e);
}
}
}
+
+ public void testCleanup() {
+ String fileName = "testCleanup.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.cleanupOnOpen", "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.cleanupOnOpen", "false");
+ }
+ }
}
diff --git a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/StreamManagerTests.java b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/StreamManagerTests.java
index ddc63a3c4..839281fd0 100644
--- a/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/StreamManagerTests.java
+++ b/bundles/org.eclipse.osgi.tests/src/org/eclipse/osgi/tests/services/datalocation/StreamManagerTests.java
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2006 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -11,10 +11,8 @@
package org.eclipse.osgi.tests.services.datalocation;
import java.io.*;
-
import junit.framework.Test;
import junit.framework.TestSuite;
-
import org.eclipse.core.runtime.Platform;
import org.eclipse.osgi.storagemanager.ManagedOutputStream;
import org.eclipse.osgi.storagemanager.StorageManager;
@@ -57,19 +55,19 @@ public class StreamManagerTests extends OSGiTest {
else
System.setProperty("osgi.useReliableFiles", reliableFile);
}
-
+
private void rm(File file) {
if (file.isDirectory()) {
File[] list = file.listFiles();
if (list != null) {
- for (int idx=0; idx<list.length; idx++) {
+ for (int idx = 0; idx < list.length; idx++) {
rm(list[idx]);
}
}
}
file.delete();
}
-
+
private String getInputStreamContents(InputStream is) throws IOException {
StringBuffer sb = new StringBuffer();
byte[] data = new byte[64];
@@ -77,14 +75,13 @@ public class StreamManagerTests extends OSGiTest {
try {
while ((len = is.read(data)) != -1) {
sb.append(new String(data, 0, len));
- }
+ }
} finally {
is.close();
}
return sb.toString();
}
-
-
+
void writeToFile(File file, String str) throws IOException {
FileOutputStream fos = new FileOutputStream(file);
try {
@@ -96,7 +93,6 @@ public class StreamManagerTests extends OSGiTest {
}
}
-
/**
* This tests that FM will keep a backup version of a reliableFile and that
* corrupting the reliableFile will recover the previous contents.
@@ -104,9 +100,9 @@ public class StreamManagerTests extends OSGiTest {
*/
public void testReliableFile() {
String fileName = "testReliableFile.txt";
- File file1 = new File(base, fileName+".1");
- File file2 = new File(base, fileName+".2");
- File file3 = new File(base, fileName+".3");
+ File file1 = new File(base, fileName + ".1");
+ File file2 = new File(base, fileName + ".2");
+ File file3 = new File(base, fileName + ".3");
String contents1 = "test reliable file cOntents #1";
String contents2 = "test reliable file cOntents #2";
try {
@@ -117,7 +113,7 @@ public class StreamManagerTests extends OSGiTest {
assertNotNull(fmos);
fmos.write(contents1.getBytes());
fmos.close();
-
+
// Write verion2 of the file
fmos = manager1.getOutputStream(fileName);
assertNotNull(fmos);
@@ -128,7 +124,7 @@ public class StreamManagerTests extends OSGiTest {
assertTrue(!file3.exists());
manager1.close();
manager1 = null;
-
+
//now, open new manager, verify file contents are #2
System.setProperty("osgi.useReliableFiles", "true"); // force reliable files
manager2 = new StorageManager(base, null);
@@ -138,11 +134,12 @@ public class StreamManagerTests extends OSGiTest {
assertEquals(contents2, getInputStreamContents(is));
manager2.close();
manager2 = null;
-
+
// need to sleep, FAT32 doesn't have too fine granularity in timestamps
try {
Thread.sleep(5000);
- } catch(InterruptedException e) {/*ignore*/}
+ } catch (InterruptedException e) {/*ignore*/
+ }
//now, corrupt version 2 of the file
RandomAccessFile raf = new RandomAccessFile(file2, "rw");
raf.seek(20);
@@ -152,12 +149,12 @@ public class StreamManagerTests extends OSGiTest {
System.setProperty("osgi.useReliableFiles", "true"); // force reliable files
manager1 = new StorageManager(base, null);
manager1.open(true);
-
+
//request any valid stream available
is = manager1.getInputStream(fileName);
assertNotNull(is);
assertEquals(contents1, getInputStreamContents(is));
-
+
//now request only the primary file
try {
InputStream[] isSet = manager1.getInputStreamSet(new String[] {fileName});
@@ -166,31 +163,32 @@ public class StreamManagerTests extends OSGiTest {
isSet[i].close();
}
fail("getInputStreamSet was successful");
- } catch(IOException e) {
+ } catch (IOException e) {
//good
}
-
+
//now, corrupt version 1 of the file
raf = new RandomAccessFile(file1, "rw");
raf.seek(20);
raf.write('0'); // change 'O' to '0'
raf.close();
-
+
// get input stream should fail
try {
is = manager1.getInputStream(fileName);
fail("get input stream succedded");
- } catch(IOException e) {
+ } catch (IOException e) {
//good
}
manager1.close();
manager1 = null;
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexepected exception", e);
+ } finally {
+ System.setProperty("osgi.useReliableFiles", "false"); // force reliable files off
}
}
-
-
+
/**
* This tests if migration from a prior (non-ReliableFile) .fileTable
* to the current .fileTable is correct.
@@ -200,8 +198,8 @@ public class StreamManagerTests extends OSGiTest {
File testDir = new File(base, "testMigrationManager");
File managerDir = new File(testDir, ".manager");
String fileName = "testMigration.txt";
- File file2 = new File(testDir, fileName+".2");
- File file5 = new File(testDir, fileName+".5");
+ File file2 = new File(testDir, fileName + ".2");
+ File file5 = new File(testDir, fileName + ".5");
File fileTable = new File(managerDir, ".fileTable");
File fileTable1 = new File(managerDir, ".fileTable.1");
File fileTable2 = new File(managerDir, ".fileTable.2");
@@ -212,14 +210,14 @@ public class StreamManagerTests extends OSGiTest {
try {
// create a .fileTable and a normal file
managerDir.mkdirs();
- writeToFile(fileTable, "#safe table\n"+fileName+"=2\n");
+ writeToFile(fileTable, "#safe table\n" + fileName + "=2\n");
writeToFile(file2, contents1);
manager1 = new StorageManager(testDir, null);
manager1.open(true);
File test = manager1.lookup(fileName, false);
assertNotNull(test);
assertTrue(test.exists());
-
+
// update a new file
File testFile = manager1.createTempFile(fileName);
writeToFile(testFile, contents2);
@@ -233,8 +231,8 @@ public class StreamManagerTests extends OSGiTest {
writeToFile(testFile, contents1);
manager1.update(new String[] {fileName}, new String[] {testFile.getName()});
manager1.close();
- manager1= null;
-
+ manager1 = null;
+
String[] files = managerDir.list();
assertEquals(4, files.length);
//original file never gets deleted
@@ -247,7 +245,7 @@ public class StreamManagerTests extends OSGiTest {
files = testDir.list();
assertEquals(2, files.length);
assertTrue(file5.exists());
-
+
manager2 = new StorageManager(testDir, null);
manager2.open(true);
testFile = manager2.lookup(fileName, false);
@@ -255,9 +253,9 @@ public class StreamManagerTests extends OSGiTest {
assertTrue(testFile.exists());
assertTrue(testFile.getName().endsWith(".5"));
manager2.close();
- manager2=null;
-
- } catch(IOException e) {
+ manager2 = null;
+
+ } catch (IOException e) {
fail("unexepected exception", e);
}
}
@@ -270,16 +268,16 @@ public class StreamManagerTests extends OSGiTest {
testAbort(true);
testAbort(false);
}
-
+
private void testAbort(boolean reliable) {
String fileName;
if (reliable)
fileName = "abortFileReliable.txt";
- else
+ else
fileName = "abortFileStd.txt";
- File file1 = new File(base, fileName+".1");
- File file2 = new File(base, fileName+".2");
- File file3 = new File(base, fileName+".3");
+ File file1 = new File(base, fileName + ".1");
+ File file2 = new File(base, fileName + ".2");
+ File file3 = new File(base, fileName + ".3");
String contents1 = "test reliable file contents #1";
String contents2 = "test reliable file contents #2";
try {
@@ -290,13 +288,13 @@ public class StreamManagerTests extends OSGiTest {
ManagedOutputStream smos = manager1.getOutputStream(fileName);
smos.write(contents1.getBytes());
smos.close();
-
+
//start creating version 2
smos = manager1.getOutputStream(fileName);
smos.write(contents2.getBytes());
smos.abort();
smos.close(); // shouldn't cause exception, check!
-
+
// now see if we're still on version #1
assertEquals(1, manager1.getId(fileName));
// check contents also
@@ -304,8 +302,8 @@ public class StreamManagerTests extends OSGiTest {
assertNotNull(is);
assertEquals(contents1, getInputStreamContents(is));
manager1.close();
- manager1=null;
-
+ manager1 = null;
+
// open a new manager & check the same thing to ensure the database is correct
System.setProperty("osgi.useReliableFiles", "true"); // force reliable files
manager2 = new StorageManager(base, null);
@@ -318,16 +316,15 @@ public class StreamManagerTests extends OSGiTest {
assertNotNull(is);
assertEquals(contents1, getInputStreamContents(is));
manager2.close();
- manager2=null;
+ manager2 = null;
assertTrue(file1.exists());
assertFalse(file2.exists());
assertFalse(file3.exists());
- } catch(IOException e) {
+ } catch (IOException e) {
fail("unexepected exception", e);
}
}
-
/**
* This tests if getting an output stream-set work properly.
*
@@ -336,7 +333,7 @@ public class StreamManagerTests extends OSGiTest {
testGetOutputStreamSet(true);
testGetOutputStreamSet(false);
}
-
+
private void testGetOutputStreamSet(boolean reliable) {
File mgrDir;
if (reliable)
@@ -345,10 +342,10 @@ public class StreamManagerTests extends OSGiTest {
mgrDir = new File(base, "getSetStd");
String fileName1 = "testSet1.txt";
String fileName2 = "testSet2.txt";
- File file1_1 = new File(mgrDir, fileName1+".1");
- File file1_2 = new File(mgrDir, fileName1+".2");
- File file2_1 = new File(mgrDir, fileName2+".1");
- File file2_2 = new File(mgrDir, fileName2+".2");
+ File file1_1 = new File(mgrDir, fileName1 + ".1");
+ File file1_2 = new File(mgrDir, fileName1 + ".2");
+ File file2_1 = new File(mgrDir, fileName2 + ".1");
+ File file2_2 = new File(mgrDir, fileName2 + ".2");
String contents1 = "test reliable file contents #1";
String contents2 = "test reliable file contents #2";
try {
@@ -358,7 +355,7 @@ public class StreamManagerTests extends OSGiTest {
ManagedOutputStream[] outs = manager1.getOutputStreamSet(new String[] {fileName1, fileName2});
assertNotNull(outs);
assertEquals(2, outs.length);
-
+
outs[0].write(contents1.getBytes());
outs[1].write(contents2.getBytes());
outs[1].close();
@@ -367,10 +364,10 @@ public class StreamManagerTests extends OSGiTest {
outs[0].close();
assertTrue(file1_1.exists());
assertTrue(file2_1.exists());
-
+
outs = manager1.getOutputStreamSet(new String[] {fileName1, fileName2});
assertNotNull(outs);
-
+
outs[0].write("new data #1".getBytes());
outs[1].write("new data #2".getBytes());
outs[0].close();
@@ -381,7 +378,7 @@ public class StreamManagerTests extends OSGiTest {
assertTrue(file2_2.exists());
manager1.close();
manager1 = null;
-
+
if (reliable) {
// verify FM thinks they are reliable
assertTrue(file1_1.exists());
@@ -389,14 +386,14 @@ public class StreamManagerTests extends OSGiTest {
} else {
// verify FM thinks they are not reliable
assertFalse(file1_1.exists());
- assertFalse(file2_1.exists());
+ assertFalse(file2_1.exists());
}
-
- } catch(IOException e) {
+
+ } catch (IOException e) {
fail("unexepected exception", e);
}
}
-
+
/**
* This tests if aborting a managed stream-set works as expected
*
@@ -405,7 +402,7 @@ public class StreamManagerTests extends OSGiTest {
testAbortSet(true);
testAbortSet(false);
}
-
+
private void testAbortSet(boolean reliable) {
File mgrDir;
if (reliable)
@@ -427,7 +424,7 @@ public class StreamManagerTests extends OSGiTest {
manager1.open(true);
ManagedOutputStream[] outs = manager1.getOutputStreamSet(new String[] {fileName1, fileName2, fileName3, fileName4});
assertNotNull(outs);
-
+
outs[0].write(contents1.getBytes());
outs[1].write(contents2.getBytes());
outs[2].write(contents2.getBytes());
@@ -449,7 +446,7 @@ public class StreamManagerTests extends OSGiTest {
assertNull(manager1.lookup(fileName4, false));
manager1.close();
manager1 = null;
-
+
// open a new manager & check the same thing to ensure the database is correct
System.setProperty("osgi.useReliableFiles", reliable ? "true" : "false"); // force reliable files
manager2 = new StorageManager(mgrDir, null);
@@ -463,10 +460,10 @@ public class StreamManagerTests extends OSGiTest {
assertEquals(1, list.length);
manager2.close();
manager2 = null;
-
- } catch(IOException e) {
+
+ } catch (IOException e) {
fail("unexepected exception", e);
}
}
-
+
}
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 baf06cda5..532014b58 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
@@ -1,5 +1,5 @@
/*******************************************************************************
- * Copyright (c) 2004, 2010 IBM Corporation and others.
+ * Copyright (c) 2004, 2011 IBM Corporation and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
@@ -87,14 +87,14 @@ public final class StorageManager {
private static final int FILETYPE_STANDARD = 0;
private static final int FILETYPE_RELIABLEFILE = 1;
private static final SecureAction secure = AccessController.doPrivileged(SecureAction.createSecureAction());
- private static final boolean tempCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanTempFiles")).booleanValue(); //$NON-NLS-1$
- private static final boolean openCleanup = Boolean.valueOf(secure.getProperty("osgi.embedded.cleanupOnOpen")).booleanValue(); //$NON-NLS-1$
private static final String MANAGER_FOLDER = ".manager"; //$NON-NLS-1$
private static final String TABLE_FILE = ".fileTable"; //$NON-NLS-1$
private static final String LOCK_FILE = ".fileTableLock"; //$NON-NLS-1$
private static final int MAX_LOCK_WAIT = 5000; // 5 seconds
- // this should be static but the tests expect to be able to create new managers after changing this setting dynamically
+ // these should be static but the tests expect to be able to create new managers after changing this setting dynamically
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 class Entry {
int readId;
@@ -554,6 +554,17 @@ public final class StorageManager {
if (error)
fileStream.abort();
}
+ // bug 259981 we should clean up
+ if (openCleanup) {
+ try {
+ cleanup(false);
+ } catch (IOException ex) {
+ // If IOException is thrown from our custom method.
+ // log and swallow for now.
+ System.out.println("Unexpected IOException is thrown inside cleanupWithLock. Please look below for stacktrace");
+ ex.printStackTrace(System.out);
+ }
+ }
tableStamp = ReliableFile.lastModifiedVersion(tableFile);
}
@@ -584,11 +595,11 @@ public final class StorageManager {
* This removal is only done if the instance of eclipse calling this method is the last instance using this storage manager.
* @throws IOException
*/
- private void cleanup() throws IOException {
+ private void cleanup(boolean doLock) throws IOException {
if (readOnly)
return;
//Lock first, so someone else can not start while we're in the middle of cleanup
- if (!lock(true))
+ if (doLock && !lock(true))
throw new IOException(EclipseAdaptorMsg.fileManager_cannotLock);
try {
//Iterate through the temp files and delete them all, except the one representing this storage manager.
@@ -636,7 +647,8 @@ public final class StorageManager {
}
}
} finally {
- release();
+ if (doLock)
+ release();
}
}
@@ -662,7 +674,7 @@ public final class StorageManager {
if (readOnly)
return;
try {
- cleanup();
+ cleanup(true);
} catch (IOException e) {
//Ignore and close.
}
@@ -680,12 +692,12 @@ public final class StorageManager {
* @throws IOException if an error occurred opening the storage manager
*/
public void open(boolean wait) throws IOException {
- if (openCleanup)
- cleanup();
if (!readOnly) {
managerRoot.mkdirs();
if (!managerRoot.exists())
throw new IOException(EclipseAdaptorMsg.fileManager_cannotLock);
+ if (openCleanup)
+ cleanup(true);
boolean locked = lock(wait);
if (!locked && wait)
throw new IOException(EclipseAdaptorMsg.fileManager_cannotLock);

Back to the top