ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bugzi...@apache.org
Subject DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"
Date Wed, 28 Sep 2011 22:11:56 GMT
https://issues.apache.org/bugzilla/show_bug.cgi?id=45786

John McNally <jmcnally@apache.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEEDINFO                    |NEW
                 CC|                            |jmcnally@apache.org

--- Comment #3 from John McNally <jmcnally@apache.org> 2011-09-28 22:11:56 UTC ---
The problem with deleting directories on NFS is likely not specific to ant. The
following code will exhibit the problem

public static boolean deleteDir(File dir) {

if (dir.isDirectory()) {
    String[] children = dir.list();

    for (int i = 0; i < children.length; i++) {
        boolean success = deleteDir(new File(dir, children[i]));
        if (!success) {  
            return false;
        }
    }
}

return dir.delete(); // this will not delete a directory containing .nfs files

}

I've found that replacing the return statement above with the following code
allows the delete to proceed to completion:

boolean isDeleted = dir.delete();
if (!isDeleted && dir.exists()) {
    // Directories mounted on NFS volumes may have lingering .nfsXXXX files
    // if no streams are open, it is likely from stale objects
    System.gc();
    try {
        Thread.sleep(100);
    } catch (InterruptedException e) {
        //ignored
    }
    isDeleted = dir.delete();
}
return isDeleted;


Not the most satisfying solution, but it works.  In this case there doesn't
seem to be any code directly making use of the files which were deleted.  But
maybe the dir.list() code used to loop over and clear the directory has some
stale objects which must be GC'ed before the directory will delete.  The slight
delay also improves the likelihood the .nfs files are removed, but is not a
substitute for the GC.

-- 
Configure bugmail: https://issues.apache.org/bugzilla/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.

Mime
View raw message