[IO-629] FileUtils#forceDelete should use Files#delete rather than
File#delete so exception messages includes reason for failure.
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 87403bd..91d059e 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -152,6 +152,9 @@
<action issue="IO-633" dev="ggregory" type="add" due-to="Gary Gregory">
Add DeletingFileVisitor.
</action>
+ <action issue="IO-629" dev="ggregory" type="update" due-to="Ian Springer, Ian Springer, Gary Gregory">
+ FileUtils#forceDelete should use Files#delete rather than File#delete so exception messages includes reason for failure.
+ </action>
</release>
<release version="2.6" date="2017-10-15" description="Java 7 required, Java 9 supported.">
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index 4e46021..baf4ec8 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -1333,15 +1333,14 @@ 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 {
- Counters.PathCounters deleteCounter;
+ final Counters.PathCounters deleteCounters;
try {
- deleteCounter = PathUtils.delete(file.toPath());
+ deleteCounters = PathUtils.delete(file.toPath());
} catch (IOException e) {
- final String message = "Unable to delete file: " + file;
- throw new IOException(message, e);
+ throw new IOException("Unable to delete file: " + file, e);
}
- if(deleteCounter.getFileCounter().get() < 1 && deleteCounter.getDirectoryCounter().get() < 1) {
+ if (deleteCounters.getFileCounter().get() < 1 && deleteCounters.getDirectoryCounter().get() < 1) {
// didn't find a file to delete.
throw new FileNotFoundException("File does not exist: " + file);
}