提交 fb14587d authored 作者: Thomas Mueller's avatar Thomas Mueller

Option to ignore problem (open files) when deleting a directory.

上级 788bc07f
...@@ -299,7 +299,7 @@ public class FullTextLucene extends FullText { ...@@ -299,7 +299,7 @@ public class FullTextLucene extends FullText {
if (index != null) { if (index != null) {
removeIndexModifier(index, path); removeIndexModifier(index, path);
} }
FileSystem.getInstance(path).deleteRecursive(path); FileSystem.getInstance(path).deleteRecursive(path, false);
} }
/** /**
......
...@@ -182,8 +182,9 @@ public abstract class FileSystem { ...@@ -182,8 +182,9 @@ public abstract class FileSystem {
* Delete a directory or file and all subdirectories and files. * Delete a directory or file and all subdirectories and files.
* *
* @param directory the directory * @param directory the directory
* @param tryOnly whether errors should be ignored
*/ */
public abstract void deleteRecursive(String directory) throws SQLException; public abstract void deleteRecursive(String directory, boolean tryOnly) throws SQLException;
/** /**
* Check if a file is read-only. * Check if a file is read-only.
......
...@@ -206,15 +206,19 @@ public class FileSystemDisk extends FileSystem { ...@@ -206,15 +206,19 @@ public class FileSystemDisk extends FileSystem {
} }
} }
public void deleteRecursive(String fileName) throws SQLException { public void deleteRecursive(String fileName, boolean tryOnly) throws SQLException {
fileName = translateFileName(fileName); fileName = translateFileName(fileName);
if (FileUtils.isDirectory(fileName)) { if (FileUtils.isDirectory(fileName)) {
String[] list = listFiles(fileName); String[] list = listFiles(fileName);
for (int i = 0; list != null && i < list.length; i++) { for (int i = 0; list != null && i < list.length; i++) {
deleteRecursive(list[i]); deleteRecursive(list[i], tryOnly);
} }
} }
delete(fileName); if (tryOnly) {
tryDelete(fileName);
} else {
delete(fileName);
}
} }
public boolean isReadOnly(String fileName) { public boolean isReadOnly(String fileName) {
......
...@@ -110,7 +110,7 @@ public class FileSystemMemory extends FileSystem { ...@@ -110,7 +110,7 @@ public class FileSystemMemory extends FileSystem {
} }
} }
public void deleteRecursive(String fileName) { public void deleteRecursive(String fileName, boolean tryOnly) {
fileName = normalize(fileName); fileName = normalize(fileName);
synchronized (MEMORY_FILES) { synchronized (MEMORY_FILES) {
Iterator<String> it = MEMORY_FILES.keySet().iterator(); Iterator<String> it = MEMORY_FILES.keySet().iterator();
......
...@@ -78,9 +78,9 @@ public class FileSystemSplit extends FileSystem { ...@@ -78,9 +78,9 @@ public class FileSystemSplit extends FileSystem {
} }
} }
public void deleteRecursive(String directory) throws SQLException { public void deleteRecursive(String directory, boolean tryOnly) throws SQLException {
directory = translateFileName(directory); directory = translateFileName(directory);
getFileSystem(directory).deleteRecursive(directory); getFileSystem(directory).deleteRecursive(directory, tryOnly);
} }
public boolean exists(String fileName) { public boolean exists(String fileName) {
......
...@@ -62,7 +62,7 @@ public class FileSystemZip extends FileSystem { ...@@ -62,7 +62,7 @@ public class FileSystemZip extends FileSystem {
throw Message.getUnsupportedException("write"); throw Message.getUnsupportedException("write");
} }
public void deleteRecursive(String fileName) throws SQLException { public void deleteRecursive(String fileName, boolean tryOnly) throws SQLException {
throw Message.getUnsupportedException("write"); throw Message.getUnsupportedException("write");
} }
......
...@@ -101,13 +101,7 @@ public class DeleteDbFiles extends Tool { ...@@ -101,13 +101,7 @@ public class DeleteDbFiles extends Tool {
private void process(String fileName, boolean quiet) throws SQLException { private void process(String fileName, boolean quiet) throws SQLException {
if (FileUtils.isDirectory(fileName)) { if (FileUtils.isDirectory(fileName)) {
try { FileSystem.getInstance(fileName).deleteRecursive(fileName, quiet);
FileSystem.getInstance(fileName).deleteRecursive(fileName);
} catch (SQLException e) {
if (!quiet) {
throw e;
}
}
} else if (quiet || fileName.endsWith(Constants.SUFFIX_TEMP_FILE) || fileName.endsWith(Constants.SUFFIX_TRACE_FILE)) { } else if (quiet || fileName.endsWith(Constants.SUFFIX_TEMP_FILE) || fileName.endsWith(Constants.SUFFIX_TRACE_FILE)) {
FileUtils.tryDelete(fileName); FileUtils.tryDelete(fileName);
} else { } else {
......
...@@ -345,10 +345,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -345,10 +345,10 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
new TestTimer().runTest(test); new TestTimer().runTest(test);
} }
} else { } else {
System.setProperty(SysProperties.H2_PAGE_STORE, "true"); // System.setProperty(SysProperties.H2_PAGE_STORE, "true");
test.pageStore = true; // test.pageStore = true;
test.runTests(); // test.runTests();
TestPerformance.main("-init", "-db", "1"); // TestPerformance.main("-init", "-db", "1");
// Recover.execute("data", null); // Recover.execute("data", null);
System.setProperty(SysProperties.H2_PAGE_STORE, "false"); System.setProperty(SysProperties.H2_PAGE_STORE, "false");
...@@ -621,7 +621,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -621,7 +621,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
void beforeTest() throws SQLException { void beforeTest() throws SQLException {
Driver.load(); Driver.load();
DeleteDbFiles.execute(TestBase.baseDir, null, true); DeleteDbFiles.execute(TestBase.baseDir, null, true);
FileSystemDisk.getInstance().deleteRecursive("trace.db"); FileSystemDisk.getInstance().deleteRecursive("trace.db", false);
if (networked) { if (networked) {
String[] args = ssl ? new String[] { "-tcpSSL", "true", "-tcpPort", "9192" } : new String[] { "-tcpPort", String[] args = ssl ? new String[] { "-tcpSSL", "true", "-tcpPort", "9192" } : new String[] { "-tcpPort",
"9192" }; "9192" };
...@@ -636,7 +636,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1` ...@@ -636,7 +636,7 @@ kill -9 `jps -l | grep "org.h2.test." | cut -d " " -f 1`
} }
private void afterTest() throws SQLException { private void afterTest() throws SQLException {
FileSystemDisk.getInstance().deleteRecursive("trace.db"); FileSystemDisk.getInstance().deleteRecursive("trace.db", false);
if (networked && server != null) { if (networked && server != null) {
server.stop(); server.stop();
} }
......
...@@ -120,8 +120,8 @@ public abstract class TestBase { ...@@ -120,8 +120,8 @@ public abstract class TestBase {
} }
} finally { } finally {
try { try {
FileSystem.getInstance("memFS:").deleteRecursive("memFS:"); FileSystem.getInstance("memFS:").deleteRecursive("memFS:", false);
FileSystem.getInstance("memLZF:").deleteRecursive("memLZF:"); FileSystem.getInstance("memLZF:").deleteRecursive("memLZF:", false);
} catch (SQLException e) { } catch (SQLException e) {
e.printStackTrace(); e.printStackTrace();
} }
......
...@@ -77,7 +77,7 @@ public class TestPerformance { ...@@ -77,7 +77,7 @@ public class TestPerformance {
if ("-db".equals(arg)) { if ("-db".equals(arg)) {
dbId = Integer.parseInt(args[++i]); dbId = Integer.parseInt(args[++i]);
} else if ("-init".equals(arg)) { } else if ("-init".equals(arg)) {
FileSystem.getInstance("data").deleteRecursive("data"); FileSystem.getInstance("data").deleteRecursive("data", true);
} else if ("-out".equals(arg)) { } else if ("-out".equals(arg)) {
out = args[++i]; out = args[++i];
} else if ("-trace".equals(arg)) { } else if ("-trace".equals(arg)) {
......
...@@ -60,7 +60,7 @@ public class TestFullText extends TestBase { ...@@ -60,7 +60,7 @@ public class TestFullText extends TestBase {
private void testCreateDrop() throws SQLException { private void testCreateDrop() throws SQLException {
deleteDb("fullText"); deleteDb("fullText");
FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullText"); FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullText", false);
Connection conn = getConnection("fullText"); Connection conn = getConnection("fullText");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
stat.execute("CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\""); stat.execute("CREATE ALIAS IF NOT EXISTS FT_INIT FOR \"org.h2.fulltext.FullText.init\"");
...@@ -71,13 +71,13 @@ public class TestFullText extends TestBase { ...@@ -71,13 +71,13 @@ public class TestFullText extends TestBase {
} }
conn.close(); conn.close();
deleteDb("fullText"); deleteDb("fullText");
FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullText"); FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullText", false);
} }
private void testReopen(boolean lucene) throws SQLException { private void testReopen(boolean lucene) throws SQLException {
String prefix = lucene ? "FTL" : "FT"; String prefix = lucene ? "FTL" : "FT";
deleteDb("fullTextReopen"); deleteDb("fullTextReopen");
FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullTextReopen"); FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullTextReopen", false);
Connection conn = getConnection("fullTextReopen"); Connection conn = getConnection("fullTextReopen");
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
String className = lucene ? "FullTextLucene" : "FullText"; String className = lucene ? "FullTextLucene" : "FullText";
...@@ -101,7 +101,7 @@ public class TestFullText extends TestBase { ...@@ -101,7 +101,7 @@ public class TestFullText extends TestBase {
private void testPerformance(boolean lucene) throws SQLException { private void testPerformance(boolean lucene) throws SQLException {
deleteDb("fullText"); deleteDb("fullText");
FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullText"); FileSystem.getInstance(baseDir).deleteRecursive(baseDir + "/fullText", false);
Connection conn = getConnection("fullText"); Connection conn = getConnection("fullText");
String prefix = lucene ? "FTL" : "FT"; String prefix = lucene ? "FTL" : "FT";
Statement stat = conn.createStatement(); Statement stat = conn.createStatement();
......
...@@ -264,7 +264,7 @@ public class FileSystemDatabase extends FileSystem { ...@@ -264,7 +264,7 @@ public class FileSystemDatabase extends FileSystem {
} }
} }
public void deleteRecursive(String fileName) throws SQLException { public void deleteRecursive(String fileName, boolean tryOnly) throws SQLException {
throw Message.getUnsupportedException("db"); throw Message.getUnsupportedException("db");
} }
......
...@@ -179,7 +179,7 @@ public class TestFileSystem extends TestBase { ...@@ -179,7 +179,7 @@ public class TestFileSystem extends TestBase {
fs.createDirs(fsBase + "/testDir/test"); fs.createDirs(fsBase + "/testDir/test");
assertTrue(fs.isDirectory(fsBase + "/testDir")); assertTrue(fs.isDirectory(fsBase + "/testDir"));
if (!fsBase.startsWith("jdbc:")) { if (!fsBase.startsWith("jdbc:")) {
fs.deleteRecursive(fsBase + "/testDir"); fs.deleteRecursive(fsBase + "/testDir", false);
assertTrue(!fs.exists(fsBase + "/testDir")); assertTrue(!fs.exists(fsBase + "/testDir"));
} }
} }
......
...@@ -71,10 +71,10 @@ public class FileSystemDebug extends FileSystem { ...@@ -71,10 +71,10 @@ public class FileSystemDebug extends FileSystem {
FileSystem.getInstance(fileName).delete(fileName); FileSystem.getInstance(fileName).delete(fileName);
} }
public void deleteRecursive(String directory) throws SQLException { public void deleteRecursive(String directory, boolean tryOnly) throws SQLException {
directory = translateFileName(directory); directory = translateFileName(directory);
debug("deleteRecursive", directory); debug("deleteRecursive", directory);
FileSystem.getInstance(directory).deleteRecursive(directory); FileSystem.getInstance(directory).deleteRecursive(directory, tryOnly);
} }
public boolean exists(String fileName) { public boolean exists(String fileName) {
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论