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 2020/12/06 14:53:23 UTC
[commons-io] branch master updated: FileUtils.forceDelete(File)
actually forces deletion of read-only files as it did in version 2.6.
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 8ae947b FileUtils.forceDelete(File) actually forces deletion of read-only files as it did in version 2.6.
8ae947b is described below
commit 8ae947bcc796d73b0eab7d94f10a002f66896af3
Author: Gary Gregory <ga...@gmail.com>
AuthorDate: Sun Dec 6 09:53:18 2020 -0500
FileUtils.forceDelete(File) actually forces deletion of read-only files
as it did in version 2.6.
---
src/changes/changes.xml | 5 ++++-
src/main/java/org/apache/commons/io/FileUtils.java | 8 ++++----
src/test/java/org/apache/commons/io/FileUtilsTestCase.java | 7 ++++---
3 files changed, 12 insertions(+), 8 deletions(-)
diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 36befd4..b439ba7 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -49,7 +49,7 @@ The <action> type attribute can be add,update,fix,remove.
<release version="2.9.0" date="2020-MM-DD" description="Java 8 required.">
<!-- FIX -->
<action issue="IO-686" dev="ggregory" type="fix" due-to="Alan Moffat, Gary Gregory">
- IOUtils.toByteArray(InputStream) Javadoc does not match code
+ IOUtils.toByteArray(InputStream) Javadoc does not match code.
</action>
<action issue="IO-689" dev="aherbert" type="fix" due-to="Uwe Schindler">
FileUtils: Remove Instant->ZonedDateTime->Instant round-trip.
@@ -71,6 +71,9 @@ The <action> type attribute can be add,update,fix,remove.
Re-implement FileUtils' iterateFiles(), iterateFilesAndDirs(), listFiles(), listFilesAndDirs() to use NIO
file tree walking instead of IO file listings to avoid memory consumption issues on large file trees.
</action>
+ <action dev="ggregory" type="fix" due-to="Gary Gregory">
+ FileUtils.forceDelete(File) actually forces deletion of read-only files as it did in version 2.6.
+ </action>
<!-- ADD -->
<action dev="ggregory" type="add" due-to="Gary Gregory">
Add FileSystemProviders class.
diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index 2df605c..0fed985 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -60,6 +60,7 @@ import org.apache.commons.io.file.AccumulatorPathVisitor;
import org.apache.commons.io.file.Counters;
import org.apache.commons.io.file.PathFilter;
import org.apache.commons.io.file.PathUtils;
+import org.apache.commons.io.file.StandardDeleteOption;
import org.apache.commons.io.filefilter.FileEqualsFileFilter;
import org.apache.commons.io.filefilter.FileFileFilter;
import org.apache.commons.io.filefilter.IOFileFilter;
@@ -1410,14 +1411,13 @@ public class FileUtils {
}
/**
- * Deletes a file. If file is a directory, delete it and all sub-directories.
+ * Deletes a file or directory. For a directory, delete it and all sub-directories.
* <p>
* The difference between File.delete() and this method are:
* </p>
* <ul>
* <li>The directory does not have to be empty.</li>
- * <li>You get exceptions when a file or directory cannot be delete;
- * {@link java.io.File#delete()} returns a boolean.</li>
+ * <li>You get an exception when a file or directory cannot be deleted.</li>
* </ul>
*
* @param file file or directory to delete, must not be {@code null}
@@ -1428,7 +1428,7 @@ public class FileUtils {
public static void forceDelete(final File file) throws IOException {
final Counters.PathCounters deleteCounters;
try {
- deleteCounters = PathUtils.delete(file.toPath());
+ deleteCounters = PathUtils.delete(file.toPath(), StandardDeleteOption.OVERRIDE_READ_ONLY);
} catch (final IOException e) {
throw new IOException("Unable to delete file: " + file, e);
}
diff --git a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
index f923c24..e03df72 100644
--- a/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
+++ b/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
@@ -118,12 +118,13 @@ public class FileUtilsTestCase {
}
}
+ /** Test data. */
private static final long DATE3 = 1000000002000L;
+ /** Test data. */
private static final long DATE2 = 1000000001000L;
- // Test data
-
+ /** Test data. */
private static final long DATE1 = 1000000000000L;
/**
@@ -1470,7 +1471,7 @@ public class FileUtilsTestCase {
assertTrue(destination.setReadOnly());
assertTrue(destination.canRead());
assertFalse(destination.canWrite());
- // sanity check
+ // sanity check that File.delete() in deletes read-only files.
assertTrue(destination.delete());
destination = File.createTempFile("test-", ".txt");
// real test