fixed bug with delete on exit deleting updated files

Former-commit-id: d26151e944f5af674c256a37694c1e5eaed4b8cc
This commit is contained in:
Jeremy Long
2013-10-05 07:40:39 -04:00
parent e2f174e92e
commit 0563077fb9

View File

@@ -80,37 +80,14 @@ public final class FileUtils {
}
}
if (!org.apache.commons.io.FileUtils.deleteQuietly(file)) {
//if (!file.delete()) {
throw new FileNotFoundException("Failed to delete file: " + file);
} else {
file.deleteOnExit();
}
}
/**
* Deletes a file. If the File is a directory it will recursively delete the
* contents.
*
* @param file the File to delete
* @param deleteOnExit setting this to true will cause errors to be ignored
* and if there is an error deleting the file it will be setup to be deleted
* when the JVM exits.
* @throws IOException is thrown if the file could not be deleted
*/
public static void delete(File file, boolean deleteOnExit) throws IOException {
if (file.isDirectory()) {
for (File c : file.listFiles()) {
delete(c);
}
}
if (!org.apache.commons.io.FileUtils.deleteQuietly(file)) {
//if (!file.delete()) {
if (deleteOnExit) {
file.deleteOnExit();
} else {
throw new FileNotFoundException("Failed to delete file: " + file);
}
}
/* else {
//delete on exit was a bad idea. if for some reason the file can't be deleted
// this will cause a newly constructed file to be deleted and a subsequent run may fail.
// still not sure why a file fails to be deleted, but can be overwritten... odd.
file.deleteOnExit();
}*/
}
/**