Skip to content

Commit

Permalink
Merge 067d63a into b06408a
Browse files Browse the repository at this point in the history
  • Loading branch information
jeromehollon committed Oct 28, 2019
2 parents b06408a + 067d63a commit 74c1770
Showing 1 changed file with 13 additions and 12 deletions.
25 changes: 13 additions & 12 deletions src/main/java/org/apache/commons/io/FileUtils.java
Expand Up @@ -45,6 +45,8 @@
import java.util.zip.CheckedInputStream;
import java.util.zip.Checksum;

import org.apache.commons.io.file.Counters;
import org.apache.commons.io.file.PathUtils;
import org.apache.commons.io.filefilter.DirectoryFileFilter;
import org.apache.commons.io.filefilter.FalseFileFilter;
import org.apache.commons.io.filefilter.FileFilterUtils;
Expand Down Expand Up @@ -1331,18 +1333,17 @@ private static void doCopyFile(final File srcFile, final File destFile, final bo
* @throws IOException in case deletion is unsuccessful
*/
public static void forceDelete(final File file) throws IOException {
if (file.isDirectory()) {
deleteDirectory(file);
} else {
final boolean filePresent = file.exists();
if (!file.delete()) {
if (!filePresent) {
throw new FileNotFoundException("File does not exist: " + file);
}
final String message =
"Unable to delete file: " + file;
throw new IOException(message);
}
Counters.PathCounters deleteCounter;
try {
deleteCounter = PathUtils.delete(file.toPath());
} catch (IOException e) {
final String message = "Unable to delete file: " + file;
throw new IOException(message, e);
}

if(deleteCounter.getFileCounter().get() < 1 && deleteCounter.getDirectoryCounter().get() < 1) {
// didn't find a file to delete.
throw new FileNotFoundException("File does not exist: " + file);
}
}

Expand Down

0 comments on commit 74c1770

Please sign in to comment.