antoine     2003/07/29 13:03:07

  Modified:    src/main/org/apache/tools/ant/taskdefs Mkdir.java
  Log:
  Similarly to what happens with the delete task, there seem to be race 
conditions which prevent successful directory creation on Windows.
  This change allows a second try.
  
  Revision  Changes    Path
  1.25      +19 -2     ant/src/main/org/apache/tools/ant/taskdefs/Mkdir.java
  
  Index: Mkdir.java
  ===================================================================
  RCS file: /home/cvs/ant/src/main/org/apache/tools/ant/taskdefs/Mkdir.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- Mkdir.java        9 Jul 2003 13:12:23 -0000       1.24
  +++ Mkdir.java        29 Jul 2003 20:03:07 -0000      1.25
  @@ -1,7 +1,7 @@
   /*
    * The Apache Software License, Version 1.1
    *
  - * Copyright (c) 2000,2002 The Apache Software Foundation.  All rights
  + * Copyright (c) 2000,2003 The Apache Software Foundation.  All rights
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -71,6 +71,7 @@
   
   public class Mkdir extends Task {
   
  +    private static final int MKDIR_RETRY_SLEEP_MILLIS = 10;
       /**
        * our little directory
        */
  @@ -92,7 +93,7 @@
           }
   
           if (!dir.exists()) {
  -            boolean result = dir.mkdirs();
  +            boolean result = mkdirs(dir);
               if (!result) {
                   String msg = "Directory " + dir.getAbsolutePath()
                       + " creation was not successful for an unknown reason";
  @@ -109,6 +110,22 @@
        */
       public void setDir(File dir) {
           this.dir = dir;
  +    }
  +    /**
  +     * Attempt to fix possible race condition when creating
  +     * directories on WinXP. If the mkdirs does not work,
  +     * wait a little and try again.
  +     */
  +    private boolean mkdirs(File f) {
  +        if (!f.mkdirs()) {
  +            try {
  +                Thread.sleep(MKDIR_RETRY_SLEEP_MILLIS);
  +                return f.mkdirs();
  +            } catch (InterruptedException ex) {
  +                return f.mkdirs();
  +            }
  +        }
  +        return true;
       }
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to