You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by co...@locus.apache.org on 2000/06/30 14:51:06 UTC

cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Delete.java Deltree.java

conor       00/06/30 05:51:06

  Modified:    src/main/org/apache/tools/ant/taskdefs Delete.java
                        Deltree.java
  Log:
  Detect situations when files and directories cannot be deleted.
  
  Revision  Changes    Path
  1.4       +6 -0      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Delete.java
  
  Index: Delete.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Delete.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Delete.java	2000/06/16 01:46:13	1.3
  +++ Delete.java	2000/06/30 12:51:04	1.4
  @@ -124,6 +124,9 @@
           else {
             project.log("Deleting: " + f.getAbsolutePath());
             f.delete();
  +	  if (f.exists()) {
  +	      throw new BuildException("Unable to delete file " + f.getAbsolutePath());
  +          }
           }
         }
       }
  @@ -146,6 +149,9 @@
           if (f.exists()) {
             project.log("Deleting: " + f.getAbsolutePath(), verbosity);
             f.delete();
  +	  if (f.exists()) {
  +	      throw new BuildException("Unable to delete " + f.getAbsolutePath());
  +          }
           }
         }
       }
  
  
  
  1.3       +9 -1      jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Deltree.java
  
  Index: Deltree.java
  ===================================================================
  RCS file: /home/cvs/jakarta-ant/src/main/org/apache/tools/ant/taskdefs/Deltree.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- Deltree.java	2000/02/24 01:34:45	1.2
  +++ Deltree.java	2000/06/30 12:51:05	1.3
  @@ -77,6 +77,9 @@
   	if (dir.exists()) {
   	    if (!dir.isDirectory()) {
   		dir.delete();
  +		if (dir.exists()) {
  +        	    throw new BuildException("Unable to delete file " + dir.getAbsolutePath());
  +	        }
   		return;
   		// String msg = "Given dir: " + dir.getAbsolutePath() +
   		// " is not a dir";
  @@ -108,10 +111,15 @@
   		removeDir(f);
   	    } else {
   		f.delete();
  +		if (f.exists()) {
  +        	    throw new BuildException("Unable to delete file " + f.getAbsolutePath());
  +	        }
   	    }
   	}
  -	    //        }
           dir.delete();
  +	if (dir.exists()) {
  +	    throw new BuildException("Unable to delete directory " + dir.getAbsolutePath());
  +	}
       }
   }
   
  
  
  

Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Delete.java Deltree.java

Posted by Stefan Bodewig <bo...@bost.de>.
>>>>> "CM" == Conor MacNeill <co...@m64.com> writes:

 CM> I didn't bother to see what File.delete returns. Would that be
 CM> preferable?

If delete can tell us that anything went wrong, we don't need to check
ourselves. Yes I'd prefer it (but can't check right now whether it'd
work. No Windows for me at the moment).

 CM> File.delete seems an unusual method to effectively return an
 CM> error code. If it didn't delete the thing, it should have thrown
 CM> an exception, IMHO.

You are perfectly right. File.mkdir(s) belongs into the same category
as well as File.createNewFile, renameTo, setLastModified and
setReadOnly. There are lots of questionable design decissions in
java.io.File.

Stefan

RE: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Delete.java Deltree.java

Posted by Conor MacNeill <co...@m64.com>.
Stefan,

>
> I thought File.exists() would return false in our case. What does
> Windows return on File.delete? Could we use that value instead?
>

Actually File.exists does work. My little bit of test code must have been
awry. It is actually the "access denied" that causes problems. I didn't
bother to see what File.delete returns. Would that be preferable? (aside:
File.delete seems an unusual method to effectively return an error code. If
it didn't delete the thing, it should have thrown an exception, IMHO).

Conor


Re: cvs commit: jakarta-ant/src/main/org/apache/tools/ant/taskdefs Delete.java Deltree.java

Posted by Stefan Bodewig <bo...@bost.de>.
Hi Conor,

I thought File.exists() would return false in our case. What does
Windows return on File.delete? Could we use that value instead?

Stefan