You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by se...@apache.org on 2011/08/30 15:55:45 UTC
svn commit: r1163210 - in /commons/proper/io/trunk/src: changes/changes.xml
main/java/org/apache/commons/io/FileUtils.java
Author: sebb
Date: Tue Aug 30 13:55:44 2011
New Revision: 1163210
URL: http://svn.apache.org/viewvc?rev=1163210&view=rev
Log:
IO-280 Dubious use of mkdirs() return code
Modified:
commons/proper/io/trunk/src/changes/changes.xml
commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java
Modified: commons/proper/io/trunk/src/changes/changes.xml
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/changes/changes.xml?rev=1163210&r1=1163209&r2=1163210&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Tue Aug 30 13:55:44 2011
@@ -41,6 +41,9 @@ The <action> type attribute can be add,u
<body>
<release version="1.4" date="Not yet released">
+ <action dev="sebb" type="fix" issue="IO-280" due-to="sebb">
+ Dubious use of mkdirs() return code
+ </action>
<action dev="sebb" type="fix" issue="IO-274" due-to="Frank Grimes">
Tailer returning partial lines when reaching EOF before EOL
</action>
Modified: commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java?rev=1163210&r1=1163209&r2=1163210&view=diff
==============================================================================
--- commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java (original)
+++ commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java Tue Aug 30 13:55:44 2011
@@ -324,9 +324,9 @@ public class FileUtils {
}
} else {
File parent = file.getParentFile();
- if (parent != null && parent.exists() == false) {
- if (parent.mkdirs() == false) {
- throw new IOException("File '" + file + "' could not be created");
+ if (parent != null) {
+ if (!parent.mkdirs() && !parent.isDirectory()) {
+ throw new IOException("Directory '" + parent + "' could not be created");
}
}
}
@@ -876,9 +876,10 @@ public class FileUtils {
if (srcFile.getCanonicalPath().equals(destFile.getCanonicalPath())) {
throw new IOException("Source '" + srcFile + "' and destination '" + destFile + "' are the same");
}
- if (destFile.getParentFile() != null && destFile.getParentFile().exists() == false) {
- if (destFile.getParentFile().mkdirs() == false) {
- throw new IOException("Destination '" + destFile + "' directory cannot be created");
+ File parentFile = destFile.getParentFile();
+ if (parentFile != null) {
+ if (!parentFile.mkdirs() && !parentFile.isDirectory()) {
+ throw new IOException("Destination '" + parentFile + "' directory cannot be created");
}
}
if (destFile.exists() && destFile.canWrite() == false) {
@@ -1182,7 +1183,7 @@ public class FileUtils {
throw new IOException("Destination '" + destDir + "' exists but is not a directory");
}
} else {
- if (destDir.mkdirs() == false) {
+ if (!destDir.mkdirs() && !destDir.isDirectory()) {
throw new IOException("Destination '" + destDir + "' directory cannot be created");
}
}