[ 
https://issues.apache.org/jira/browse/IO-629?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17176287#comment-17176287
 ] 

Robin Jansohn commented on IO-629:
----------------------------------

With this change 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 either through an overloaded method with additional parameter ({{boolean 
force}}) or an additional method like {{forceDelete()}}.

Opinions?

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}


> FileUtils#forceDelete should use Files#delete rather than File#delete so 
> exception messages includes reason for failure
> -----------------------------------------------------------------------------------------------------------------------
>
>                 Key: IO-629
>                 URL: https://issues.apache.org/jira/browse/IO-629
>             Project: Commons IO
>          Issue Type: Improvement
>            Reporter: Ian Springer
>            Priority: Major
>             Fix For: 2.7
>
>         Attachments: IO-629.patch
>
>          Time Spent: 3h
>  Remaining Estimate: 0h
>
> From File#delete Javadoc:
> {noformat}
> <p> Note that the {@link java.nio.file.Files} class defines the 
> {@link java.nio.file.Files#delete(Path) delete} method to throw
> an {@link IOException} when a file cannot be deleted. This is 
> useful for error reporting and to diagnose why a file cannot be
>  deleted.
> {noformat}
>  
>  This change is possible now that 2.6 requires Java 7.
>  



--
This message was sent by Atlassian Jira
(v8.3.4#803005)

Reply via email to