The Apache Ant Mkdir calls the File.mkdirs() method, which is vulnerable to race conditions .
File.mkdirs() not an atomic operation - I assume that it is implemented as a sequence of calls to Mkdir .
In the case of a remote file system, there is a good chance that your host will find out about file system changes in the middle of the File.mkdirs() operation, and it will not work.
Ant seemed to try to fix it as Mkdir code changed from this to 1.8.0
boolean result = mkdirs(dir); if (!result) { String msg = "Directory " + dir.getAbsolutePath() + " creation was not successful for an unknown reason"; throw new BuildException(msg, getLocation()); }
to this in 1.8.2
boolean result = mkdirs(dir); if (!result) { if (dir.exists()) { log("A different process or task has already created " + "dir " + dir.getAbsolutePath(), Project.MSG_VERBOSE); return; } String msg = "Directory " + dir.getAbsolutePath() + " creation was not successful for an unknown reason"; throw new BuildException(msg, getLocation()); }
Is it possible to upgrade to the latest version of Ant?
If not, some brute force extension Mkdir can be created using a native implementation of the execute() method.
If not, Ant Contrib's Trycatch task will work.
Oleg Mikheev
source share