diff options
author | Matthias Sohn <matthias.sohn@sap.com> | 2019-07-16 16:34:56 +0200 |
---|---|---|
committer | Matthias Sohn <matthias.sohn@sap.com> | 2019-07-26 15:53:33 +0200 |
commit | 902935c38c0f1e9e8ecb0fce24c63cb06c07c963 (patch) | |
tree | cd821d272c51aa71eb8b28755b97a52b96a8c4b7 /org.eclipse.jgit.junit/src | |
parent | d17efe880d0bb16c966dcc6fb55a98f46afc4508 (diff) | |
download | jgit-902935c38c0f1e9e8ecb0fce24c63cb06c07c963.tar.gz jgit-902935c38c0f1e9e8ecb0fce24c63cb06c07c963.zip |
Reuse FileUtils to recursively delete files created by tests
Replace redundant complex implementation of recursive delete by the one
in FileUtils.
Change-Id: Iced1468b96c4f32381a9cf0c651b2bf6a9a9af35
Signed-off-by: Matthias Sohn <matthias.sohn@sap.com>
Diffstat (limited to 'org.eclipse.jgit.junit/src')
-rw-r--r-- | org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java | 42 |
1 files changed, 19 insertions, 23 deletions
diff --git a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java index af688d2349..62dfc5d9c0 100644 --- a/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java +++ b/org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java @@ -51,6 +51,7 @@ import static org.junit.Assert.fail; import java.io.File; import java.io.IOException; +import java.io.PrintStream; import java.time.Instant; import java.util.ArrayList; import java.util.Collections; @@ -237,35 +238,30 @@ public abstract class LocalDiskRepositoryTestCase { private static boolean recursiveDelete(final File dir, boolean silent, boolean failOnError) { assert !(silent && failOnError); - if (!dir.exists()) - return silent; - final File[] ls = dir.listFiles(); - if (ls != null) - for (int k = 0; k < ls.length; k++) { - final File e = ls[k]; - if (e.isDirectory()) - silent = recursiveDelete(e, silent, failOnError); - else if (!e.delete()) { - if (!silent) - reportDeleteFailure(failOnError, e); - silent = !failOnError; - } - } - if (!dir.delete()) { - if (!silent) - reportDeleteFailure(failOnError, dir); - silent = !failOnError; + int options = FileUtils.RECURSIVE | FileUtils.RETRY + | FileUtils.SKIP_MISSING; + if (silent) { + options |= FileUtils.IGNORE_ERRORS; } - return silent; + try { + FileUtils.delete(dir, options); + } catch (IOException e) { + reportDeleteFailure(failOnError, dir, e); + return !failOnError; + } + return true; } - private static void reportDeleteFailure(boolean failOnError, File e) { + private static void reportDeleteFailure(boolean failOnError, File f, + Exception cause) { String severity = failOnError ? "ERROR" : "WARNING"; - String msg = severity + ": Failed to delete " + e; - if (failOnError) + String msg = severity + ": Failed to delete " + f; + if (failOnError) { fail(msg); - else + } else { System.err.println(msg); + } + cause.printStackTrace(new PrintStream(System.err)); } /** Constant <code>MOD_TIME=1</code> */ |