From 4d60eb31973d38c81a1ca913d770aae3ad64839c Mon Sep 17 00:00:00 2001 From: Antoine Levy-Lambert Date: Tue, 29 Jul 2003 20:03:07 +0000 Subject: [PATCH] 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 --- .../org/apache/tools/ant/taskdefs/Mkdir.java | 21 +++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/src/main/org/apache/tools/ant/taskdefs/Mkdir.java b/src/main/org/apache/tools/ant/taskdefs/Mkdir.java index 5266e5a54..a9a9736f4 100644 --- a/src/main/org/apache/tools/ant/taskdefs/Mkdir.java +++ b/src/main/org/apache/tools/ant/taskdefs/Mkdir.java @@ -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; + } }