FileUtils.forceDelete(File) actually forces deletion of read-only files
as it did in version 2.6.
MODIFY
src/changes/changes.xml
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.

MODIFY
src/main/java/org/apache/commons/io/FileUtils.java
src/main/java/org/apache/commons/io/FileUtils.java
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 @@ private static void doCopyFile(final File srcFile, final File destFile, final bo
}
/**
- * 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 @@ private static void doCopyFile(final File srcFile, final File destFile, final bo
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);
}

MODIFY
src/test/java/org/apache/commons/io/FileUtilsTestCase.java
src/test/java/org/apache/commons/io/FileUtilsTestCase.java
@@ -118,12 +118,13 @@ public long length() {
}
}
+ /** 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 void testForceDeleteReadOnlyFile() throws Exception {
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

FileUtils.forceDelete(File) actually forces deletion of read-only files
as it did in version 2.6.