Browse Source

weed out race-condition in mkdirs calls inspired by PR 55290 and Matthias Bhend's suggestion

git-svn-id: https://svn.apache.org/repos/asf/ant/core/trunk@1554403 13f79535-47bb-0310-9956-ffa450edef68
master
Stefan Bodewig 11 years ago
parent
commit
234c1d9ff4
15 changed files with 39 additions and 20 deletions
  1. +1
    -0
      CONTRIBUTORS
  2. +4
    -0
      WHATSNEW
  3. +16
    -8
      contributors.xml
  4. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Copy.java
  5. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/Move.java
  6. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/Tar.java
  7. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java
  8. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/Zip.java
  9. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java
  10. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java
  11. +2
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java
  12. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java
  13. +1
    -1
      src/main/org/apache/tools/ant/taskdefs/optional/sos/SOS.java
  14. +2
    -1
      src/main/org/apache/tools/ant/util/FileUtils.java
  15. +1
    -1
      src/main/org/apache/tools/ant/util/ResourceUtils.java

+ 1
- 0
CONTRIBUTORS View File

@@ -239,6 +239,7 @@ Matthew Hawthorne
Matthew Inger Matthew Inger
Matthew Kuperus Heun Matthew Kuperus Heun
Matthew Watson Matthew Watson
Matthias Bhend
Michael Bayne Michael Bayne
Michael Clarke Michael Clarke
Michael Davey Michael Davey


+ 4
- 0
WHATSNEW View File

@@ -17,6 +17,10 @@ Fixed bugs:
different resource types. different resource types.
Bugzilla Report 55097 Bugzilla Report 55097


* several calls to File#mkdirs could fall victim to a race condition
where another thread already created the same directory.
Bugzilla Report 55290

Other changes: Other changes:
-------------- --------------




+ 16
- 8
contributors.xml View File

@@ -924,14 +924,6 @@
<first>Martin</first> <first>Martin</first>
<last>von Gagern</last> <last>von Gagern</last>
</name> </name>
<name>
<first>Mathieu</first>
<last>Champlon</last>
</name>
<name>
<first>Mathieu</first>
<last>Peltier</last>
</name>
<name> <name>
<first>Matt</first> <first>Matt</first>
<last>Albrecht</last> <last>Albrecht</last>
@@ -960,6 +952,22 @@
<first>Matt</first> <first>Matt</first>
<last>Small</last> <last>Small</last>
</name> </name>
<name>
<first>Matt</first>
<last>Wildig</last>
</name>
<name>
<first>Mathieu</first>
<last>Champlon</last>
</name>
<name>
<first>Mathieu</first>
<last>Peltier</last>
</name>
<name>
<first>Matthias</first>
<last>Bhend</last>
</name>
<name> <name>
<first>Matthew</first> <first>Matthew</first>
<last>Hawthorne</last> <last>Hawthorne</last>


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Copy.java View File

@@ -915,7 +915,7 @@ public class Copy extends Task {
for (int i = 0; i < dirs.length; i++) { for (int i = 0; i < dirs.length; i++) {
File d = new File(dirs[i]); File d = new File(dirs[i]);
if (!d.exists()) { if (!d.exists()) {
if (!d.mkdirs()) {
if (!(d.mkdirs() || d.isDirectory())) {
log("Unable to create directory " log("Unable to create directory "
+ d.getAbsolutePath(), Project.MSG_ERR); + d.getAbsolutePath(), Project.MSG_ERR);
} else { } else {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/Move.java View File

@@ -178,7 +178,7 @@ public class Move extends Copy {
} }
File d = new File(toDirNames[i]); File d = new File(toDirNames[i]);
if (!d.exists()) { if (!d.exists()) {
if (!d.mkdirs()) {
if (!(d.mkdirs() || d.exists())) {
log("Unable to create directory " log("Unable to create directory "
+ d.getAbsolutePath(), Project.MSG_ERR); + d.getAbsolutePath(), Project.MSG_ERR);
} else { } else {


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/Tar.java View File

@@ -281,7 +281,8 @@ public class Tar extends MatchingTask {
} }


File parent = tarFile.getParentFile(); File parent = tarFile.getParentFile();
if (parent != null && !parent.isDirectory() && !parent.mkdirs()) {
if (parent != null && !parent.isDirectory()
&& !(parent.mkdirs() || parent.isDirectory())) {
throw new BuildException("Failed to create missing parent" throw new BuildException("Failed to create missing parent"
+ " directory for " + tarFile); + " directory for " + tarFile);
} }


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/XSLTProcess.java View File

@@ -896,7 +896,7 @@ public class XSLTProcess extends MatchingTask implements XSLTLogger {
private void ensureDirectoryFor(File targetFile) throws BuildException { private void ensureDirectoryFor(File targetFile) throws BuildException {
File directory = targetFile.getParentFile(); File directory = targetFile.getParentFile();
if (!directory.exists()) { if (!directory.exists()) {
if (!directory.mkdirs()) {
if (!(directory.mkdirs() || directory.isDirectory())) {
handleError("Unable to create directory: " handleError("Unable to create directory: "
+ directory.getAbsolutePath()); + directory.getAbsolutePath());
} }


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/Zip.java View File

@@ -645,7 +645,8 @@ public class Zip extends MatchingTask {
} }


File parent = zipFile.getParentFile(); File parent = zipFile.getParentFile();
if (parent != null && !parent.isDirectory() && !parent.mkdirs()) {
if (parent != null && !parent.isDirectory()
&& !(parent.mkdirs() || parent.isDirectory())) {
throw new BuildException("Failed to create missing parent" throw new BuildException("Failed to create missing parent"
+ " directory for " + zipFile); + " directory for " + zipFile);
} }


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/compilers/Gcj.java View File

@@ -87,7 +87,8 @@ public class Gcj extends DefaultCompilerAdapter {
cmd.createArgument().setValue("-d"); cmd.createArgument().setValue("-d");
cmd.createArgument().setFile(destDir); cmd.createArgument().setFile(destDir);


if (!destDir.exists() && !destDir.mkdirs()) {
if (!destDir.exists()
&& !(destDir.mkdirs() || destDir.isDirectory())) {
throw new BuildException("Can't make output directories. " throw new BuildException("Can't make output directories. "
+ "Maybe permission is wrong. "); + "Maybe permission is wrong. ");
} }


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/optional/Native2Ascii.java View File

@@ -279,7 +279,8 @@ public class Native2Ascii extends MatchingTask {
if (parentName != null) { if (parentName != null) {
File parentFile = new File(parentName); File parentFile = new File(parentName);


if ((!parentFile.exists()) && (!parentFile.mkdirs())) {
if (!parentFile.exists()
&& !(parentFile.mkdirs() || parentFile.isDirectory())) {
throw new BuildException("cannot create parent directory " throw new BuildException("cannot create parent directory "
+ parentName); + parentName);
} }


+ 2
- 1
src/main/org/apache/tools/ant/taskdefs/optional/image/Image.java View File

@@ -305,7 +305,8 @@ public class Image extends MatchingTask {
} }


File dstParent = newFile.getParentFile(); File dstParent = newFile.getParentFile();
if (!dstParent.isDirectory() && !dstParent.mkdirs()){
if (!dstParent.isDirectory()
&& !(dstParent.mkdirs() || dstParent.isDirectory())) {
throw new BuildException("Failed to create parent directory " throw new BuildException("Failed to create parent directory "
+ dstParent); + dstParent);
} }


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/pvcs/Pvcs.java View File

@@ -319,7 +319,7 @@ public class Pvcs extends org.apache.tools.ant.Task {
if (!dir.exists()) { if (!dir.exists()) {
log("Creating " + dir.getAbsolutePath(), log("Creating " + dir.getAbsolutePath(),
Project.MSG_VERBOSE); Project.MSG_VERBOSE);
if (dir.mkdirs()) {
if (dir.mkdirs() || dir.isDirectory()) {
log("Created " + dir.getAbsolutePath(), log("Created " + dir.getAbsolutePath(),
Project.MSG_INFO); Project.MSG_INFO);
} else { } else {


+ 1
- 1
src/main/org/apache/tools/ant/taskdefs/optional/sos/SOS.java View File

@@ -362,7 +362,7 @@ public abstract class SOS extends Task implements SOSCmd {
// make sure localDir exists, create it if it doesn't // make sure localDir exists, create it if it doesn't
File dir = getProject().resolveFile(localPath); File dir = getProject().resolveFile(localPath);
if (!dir.exists()) { if (!dir.exists()) {
boolean done = dir.mkdirs();
boolean done = dir.mkdirs() || dir.isDirectory();
if (!done) { if (!done) {
String msg = "Directory " + localPath + " creation was not " String msg = "Directory " + localPath + " creation was not "
+ "successful for an unknown reason"; + "successful for an unknown reason";


+ 2
- 1
src/main/org/apache/tools/ant/util/FileUtils.java View File

@@ -1308,7 +1308,8 @@ public class FileUtils {
throw new IOException("Failed to delete " + to + " while trying to rename " + from); throw new IOException("Failed to delete " + to + " while trying to rename " + from);
} }
File parent = to.getParentFile(); File parent = to.getParentFile();
if (parent != null && !parent.exists() && !parent.mkdirs()) {
if (parent != null && !parent.isDirectory()
&& !(parent.mkdirs() || parent.isDirectory())) {
throw new IOException("Failed to create directory " + parent throw new IOException("Failed to create directory " + parent
+ " while trying to rename " + from); + " while trying to rename " + from);
} }


+ 1
- 1
src/main/org/apache/tools/ant/util/ResourceUtils.java View File

@@ -513,7 +513,7 @@ public class ResourceUtils {


File parent = destFile.getParentFile(); File parent = destFile.getParentFile();
if (parent != null && !parent.isDirectory() if (parent != null && !parent.isDirectory()
&& !destFile.getParentFile().mkdirs()) {
&& !(parent.mkdirs() || parent.isDirectory())) {
throw new IOException("failed to create the parent directory" throw new IOException("failed to create the parent directory"
+ " for " + destFile); + " for " + destFile);
} }


Loading…
Cancel
Save