ant-notifications mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
Subject DO NOT REPLY [Bug 45786] ANT and NFS, Delete task - "Unable to delete directory"
Date Wed, 28 Sep 2011 22:11:56 GMT

John McNally <> changed:

           What    |Removed                     |Added
             Status|NEEDINFO                    |NEW
                 CC|                            |

--- Comment #3 from John McNally <> 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
    try {
    } catch (InterruptedException e) {
    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:
------- You are receiving this mail because: -------
You are the assignee for the bug.

View raw message