Skip to content

Commit 9e8d03a

Browse files
author
Michiel Kalkman
authored
Tiny performance improvement in FileUtils#moveDirectoryToDirectory() (#174)
* Tiny performance improvements. * Optimizing number of I/O related calls * fix checkstyle issue * if a file is a directory, it exists, so no need to test for existence; reducing File calls
1 parent 2c1418d commit 9e8d03a

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

src/main/java/org/apache/commons/io/FileUtils.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2127,17 +2127,17 @@ public static void moveDirectory(final File srcDir, final File destDir) throws I
21272127
public static void moveDirectoryToDirectory(final File src, final File destDir, final boolean createDestDir)
21282128
throws IOException {
21292129
validateMoveParameters(src, destDir);
2130-
if (!destDir.exists() && createDestDir) {
2131-
if (!destDir.mkdirs()) {
2132-
throw new IOException("Could not create destination directories '" + destDir + "'");
2133-
}
2134-
}
2135-
if (!destDir.exists()) {
2136-
throw new FileNotFoundException("Destination directory '" + destDir +
2137-
"' does not exist [createDestDir=" + createDestDir + "]");
2138-
}
21392130
if (!destDir.isDirectory()) {
2140-
throw new IOException("Destination '" + destDir + "' is not a directory");
2131+
if (destDir.exists()) {
2132+
throw new IOException("Destination '" + destDir + "' is not a directory");
2133+
} else if (createDestDir) {
2134+
if (!destDir.mkdirs()) {
2135+
throw new IOException("Could not create destination directories '" + destDir + "'");
2136+
}
2137+
} else {
2138+
throw new FileNotFoundException("Destination directory '" + destDir +
2139+
"' does not exist [createDestDir=" + createDestDir + "]");
2140+
}
21412141
}
21422142
moveDirectory(src, new File(destDir, src.getName()));
21432143
}

0 commit comments

Comments
 (0)