Parcourir la source

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>
tags/v5.1.9.201908210455-r
Matthias Sohn il y a 4 ans
Parent
révision
902935c38c

+ 19
- 23
org.eclipse.jgit.junit/src/org/eclipse/jgit/junit/LocalDiskRepositoryTestCase.java Voir le fichier

@@ -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> */

Chargement…
Annuler
Enregistrer