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

Gary D. Gregory commented on IO-850:
------------------------------------

[~jcompan...@gmail.com] 

I cannot reproduce your text in a unit test, please see 
[https://github.com/apache/commons-io/blob/08b3ea4ed7c09b65260d1929d42b9a5c39d5007a/src/test/java/org/apache/commons/io/file/DeletingPathVisitorTest.java#L121-L157]
{code:java}
    /**
     * Tests https://issues.apache.org/jira/browse/IO-850
     */
    @Test
    public void testIO850DirectoriesOnly() throws IOException {
        final Path rootDir = 
Files.createDirectory(managedTempDirPath.resolve("IO850"));
        createTempSymlinkedRelativeDir(rootDir);
        final Path targetDir = rootDir.resolve(SUB_DIR);
        final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR);
        final DeletingPathVisitor visitor = 
DeletingPathVisitor.withLongCounters();
        Files.walkFileTree(rootDir, visitor);
        assertFalse(Files.exists(targetDir));
        assertFalse(Files.exists(symlinkDir));
        assertFalse(Files.exists(rootDir));
        assertTrue(visitor.getPathCounters().getDirectoryCounter().get() > 0);
    }

    /**
     * Tests https://issues.apache.org/jira/browse/IO-850
     */
    @Test
    public void testIO850DirectoriesAndFiles() throws IOException {
        final Path rootDir = 
Files.createDirectory(managedTempDirPath.resolve("IO850"));
        createTempSymlinkedRelativeDir(rootDir);
        final Path targetDir = rootDir.resolve(SUB_DIR);
        final Path symlinkDir = rootDir.resolve(SYMLINKED_DIR);
        Files.write(targetDir.resolve("file0.txt"), 
"Hello".getBytes(StandardCharsets.UTF_8));
        final Path subDir0 = 
Files.createDirectory(targetDir.resolve("subDir0"));
        Files.write(subDir0.resolve("file1.txt"), 
"Hello".getBytes(StandardCharsets.UTF_8));
        final DeletingPathVisitor visitor = 
DeletingPathVisitor.withLongCounters();
        Files.walkFileTree(rootDir, visitor);
        assertFalse(Files.exists(targetDir));
        assertFalse(Files.exists(symlinkDir));
        assertFalse(Files.exists(rootDir));
        assertTrue(visitor.getPathCounters().getDirectoryCounter().get() > 0);
        assertTrue(visitor.getPathCounters().getFileCounter().get() > 0);
    }
{code}
Would you please review and test with the current release {*}2.16.0{*}? 
TY 

> DeletingPathVisitor always fails to delete a dir when symbolic link target is 
> deleted before the link itself
> ------------------------------------------------------------------------------------------------------------
>
>                 Key: IO-850
>                 URL: https://issues.apache.org/jira/browse/IO-850
>             Project: Commons IO
>          Issue Type: Bug
>    Affects Versions: 2.15.1
>            Reporter: Johan Compagner
>            Priority: Major
>
> DeletingPathVisitor doesn't give us an option for the SimplePathVisitor 
> superclass visitFileFailedFunction property (that constructor also exposed to 
> the intermediate class CountingPathVisitor is not used/exposed in the 
> DeletingPathVisitor class)
> So i can't use that but the DeletingPathVisitor should use that, because i 
> can't delete a certain directory if you have something like this:
>  
> parentdir:
>   adir
>   symboliclinkpointingtoadir
>  
> if that happens and i call this Files.walkFileTree(path, 
> DeletingPathVisitor.withLongCounters());
> on the parent dir and it first deletes "adir" 
> then it will completely fail to delete that parentdir (or clean the parent 
> dir)
> this is because Files will try to open the directory stream of that 
> "symboliclinkpointingtoadir" and that will fail because the "adir" is already 
> gone. so its now an invalid symbolic link. The the Files walkFileTree 
> implementation does call visitFileFailed but that is competely not 
> implemented in the DeletingPathVisitor and i have no means of also adding it 
> to it.
> i think DeletingPathVisitor should just do what i now do in my own 
> implementation:
>  
>  
> {code:java}
>                                     public FileVisitResult 
> visitFileFailed(Path file, IOException exc) throws IOException
>                                     {
>                                         Files.deleteIfExists(file);
>                                         return FileVisitResult.CONTINUE;
>                                     }
>  
> {code}
> just try to delete that file and be done with it (this works fine)
> now it bombs out because that IOException is something like "FileNotFound" 
> and if if i call it again and again on that dir (so "adir" is already gone) 
> the DeletingPathVisitor is never able to delete/clean that parent dir it 
> always bombs out.
>  



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to