You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@ant.apache.org by pe...@apache.org on 2003/07/14 19:29:17 UTC

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

peterreilly    2003/07/14 10:29:17

  Modified:    src/main/org/apache/tools/ant/taskdefs Delete.java
  Log:
  fix for possible race condition on windows
  
  Revision  Changes    Path
  1.42      +22 -6     ant/src/main/org/apache/tools/ant/taskdefs/Delete.java
  
  Index: Delete.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Delete.java,v
  retrieving revision 1.41
  retrieving revision 1.42
  diff -u -r1.41 -r1.42
  --- Delete.java	6 Jul 2003 09:57:36 -0000	1.41
  +++ Delete.java	14 Jul 2003 17:29:17 -0000	1.42
  @@ -459,7 +459,7 @@
                   } else {
                       log("Deleting: " + file.getAbsolutePath());
   
  -                    if (!file.delete()) {
  +                    if (!delete(file)) {
                           String message = "Unable to delete file "
                               + file.getAbsolutePath();
                           if (failonerror) {
  @@ -534,7 +534,23 @@
   //************************************************************************
   //  protected and private methods
   //************************************************************************
  -
  +    /**
  +     * Attempt to fix possible race condition when deleting
  +     * files on WinXP. If the delete does not work,
  +     * wait a little and try again.
  +     */
  +    private boolean delete(File f) {
  +        if (! f.delete()) {
  +            try {
  +                Thread.sleep(10);
  +                return f.delete();
  +            } catch (InterruptedException ex) {
  +                return f.delete();
  +            }
  +        }
  +        return true;
  +    }
  +    
       protected void removeDir(File d) {
           String[] list = d.list();
           if (list == null) {
  @@ -547,7 +563,7 @@
                   removeDir(f);
               } else {
                   log("Deleting " + f.getAbsolutePath(), verbosity);
  -                if (!f.delete()) {
  +                if (!delete(f)) {
                       String message = "Unable to delete file "
                           + f.getAbsolutePath();
                       if (failonerror) {
  @@ -560,7 +576,7 @@
               }
           }
           log("Deleting directory " + d.getAbsolutePath(), verbosity);
  -        if (!d.delete()) {
  +        if (!delete(d)) {
               String message = "Unable to delete directory "
                   + dir.getAbsolutePath();
               if (failonerror) {
  @@ -586,7 +602,7 @@
               for (int j = 0; j < files.length; j++) {
                   File f = new File(d, files[j]);
                   log("Deleting " + f.getAbsolutePath(), verbosity);
  -                if (!f.delete()) {
  +                if (!delete(f)) {
                       String message = "Unable to delete file "
                           + f.getAbsolutePath();
                       if (failonerror) {
  @@ -606,7 +622,7 @@
                   String[] dirFiles = dir.list();
                   if (dirFiles == null || dirFiles.length == 0) {
                       log("Deleting " + dir.getAbsolutePath(), verbosity);
  -                    if (!dir.delete()) {
  +                    if (!delete(dir)) {
                           String message = "Unable to delete directory "
                                   + dir.getAbsolutePath();
                           if (failonerror) {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org