Browse Source

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.


git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@274985 13f79535-47bb-0310-9956-ffa450edef68
master
Antoine Levy-Lambert 22 years ago
parent
commit
4d60eb3197
1 changed files with 19 additions and 2 deletions
  1. +19
    -2
      src/main/org/apache/tools/ant/taskdefs/Mkdir.java

+ 19
- 2
src/main/org/apache/tools/ant/taskdefs/Mkdir.java View File

@@ -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 @@ import org.apache.tools.ant.Task;

public class Mkdir extends Task {

private static final int MKDIR_RETRY_SLEEP_MILLIS = 10;
/**
* our little directory
*/
@@ -92,7 +93,7 @@ public class Mkdir extends Task {
}

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";
@@ -110,5 +111,21 @@ public class Mkdir extends Task {
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;
}
}


Loading…
Cancel
Save