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