[
https://issues.apache.org/jira/browse/IO-684?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17329900#comment-17329900
]
Bryan Turner commented on IO-684:
---------------------------------
One thing the changes here don't address is the altered behavior of
{{FileUtils.cleanDirectory}} (and other helpers that use it, like
{{deleteDirectory}} and {{deleteQuietly}}). Because commons-io 2.6 used
{{File.delete}}, it would delete read-only files by default. However, with
{{FileUtils.forceDelete}} now updated to call
{{PathUtils.delete(file.toPath())}} without
{{StandardDeleteOption.OVERRIDE_READ_ONLY}}, this no longer works. It also
doesn't appear any overloads were added in {{FileUtils}} to get the old
behavior back again.
This behavior change is causing a lot of subtle breakages in code that I
maintain, as well as code that I use. Should the {{FileUtils}} variants perhaps
be updated to restore the old behavior by default? Or perhaps some overloads
added to callers can easily restore the old behavior if they need to after
upgrading?
> Add force version of PathUtils.delete() APIs and friends.
> ---------------------------------------------------------
>
> Key: IO-684
> URL: https://issues.apache.org/jira/browse/IO-684
> Project: Commons IO
> Issue Type: Bug
> Components: Utilities
> Affects Versions: 2.7
> Reporter: Robin Jansohn
> Priority: Major
> Fix For: 2.8.0
>
>
> With the changes from IO-629 I'm getting an {{AccessDeniedException}} when
> trying to recursively delete a directory with read-only files, e.g. a
> {{.git}} repository. Before this change the directory was successfully
> deleted. It is due to the difference between {{File.delete()}} and
> {{Files.delete()}} (see https://stackoverflow.com/a/12234217/3375325).
> I think an option should be introduced to make the previous behavior
> available again with an overloaded method like {{PathUtils.delete(Path path,
> boolean force)}}.
> Stacktrace:
> {noformat}
> java.nio.file.AccessDeniedException:
> C:\Users\xyz\AppData\Local\Temp\.git\objects\pack\pack-6576964fbde069f1787513ce358d2260530d5738.idx
> at
> sun.nio.fs.WindowsException.translateToIOException(WindowsException.java:83)
> at
> sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:97)
> at
> sun.nio.fs.WindowsException.rethrowAsIOException(WindowsException.java:102)
> at
> sun.nio.fs.WindowsFileSystemProvider.implDelete(WindowsFileSystemProvider.java:269)
> at
> sun.nio.fs.AbstractFileSystemProvider.deleteIfExists(AbstractFileSystemProvider.java:108)
> at java.nio.file.Files.deleteIfExists(Files.java:1165)
> at
> org.apache.commons.io.file.DeletingPathVisitor.visitFile(DeletingPathVisitor.java:99)
> at
> org.apache.commons.io.file.DeletingPathVisitor.visitFile(DeletingPathVisitor.java:35)
> at java.nio.file.Files.walkFileTree(Files.java:2670)
> at java.nio.file.Files.walkFileTree(Files.java:2742)
> at
> org.apache.commons.io.file.PathUtils.visitFileTree(PathUtils.java:535)
> at
> org.apache.commons.io.file.PathUtils.deleteDirectory(PathUtils.java:265)
> at org.apache.commons.io.file.PathUtils.delete(PathUtils.java:254)
> {noformat}
--
This message was sent by Atlassian Jira
(v8.3.4#803005)