You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2019/10/28 17:53:14 UTC
[commons-io] branch master updated: [IO-629] FileUtils#forceDelete
should use Files#delete rather than File#delete so exception messages
includes reason for failure.
This is an automated email from the ASF dual-hosted git repository.
ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git
The following commit(s) were added to refs/heads/master by this push:
new b0bbc43 [IO-629] FileUtils#forceDelete should use Files#delete rather than File#delete so exception messages includes reason for failure.
b0bbc43 is described below
commit b0bbc434e40f95bbc8f5aee2cb68b3f6a1ed7968
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Mon Oct 28 13:52:47 2019 -0400
[IO-629] FileUtils#forceDelete should use Files#delete rather than
File#delete so exception messages includes reason for failure.
---
src/changes/changes.xml | 3 +++
src/main/java/org/apache/commons/io/FileUtils.java | 9 ++++-----
2 files changed, 7 insertions(+), 5 deletions(-)
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 @@ The <action> type attribute can be add,update,fix,remove.
<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 @@ public class FileUtils {
* @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);
}