You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2021/01/01 03:18:14 UTC

[commons-io] branch master updated: Tiny performance improvement in FileUtils#moveDirectoryToDirectory() (#174)

This is an automated email from the ASF dual-hosted git repository.

ggregory pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-io.git


The following commit(s) were added to refs/heads/master by this push:
     new 9e8d03a  Tiny performance improvement in FileUtils#moveDirectoryToDirectory() (#174)
9e8d03a is described below

commit 9e8d03a2ef565d32d09c795e1e29642ba48bd1c7
Author: Michiel Kalkman <mi...@atos.net>
AuthorDate: Fri Jan 1 04:18:07 2021 +0100

    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
---
 src/main/java/org/apache/commons/io/FileUtils.java | 20 ++++++++++----------
 1 file changed, 10 insertions(+), 10 deletions(-)

diff --git a/src/main/java/org/apache/commons/io/FileUtils.java b/src/main/java/org/apache/commons/io/FileUtils.java
index ed0db1f..0944471 100644
--- a/src/main/java/org/apache/commons/io/FileUtils.java
+++ b/src/main/java/org/apache/commons/io/FileUtils.java
@@ -2127,17 +2127,17 @@ public class FileUtils {
     public static void moveDirectoryToDirectory(final File src, final File destDir, final boolean createDestDir)
             throws IOException {
         validateMoveParameters(src, destDir);
-        if (!destDir.exists() && createDestDir) {
-            if (!destDir.mkdirs()) {
-                throw new IOException("Could not create destination directories '" + destDir + "'");
-            }
-        }
-        if (!destDir.exists()) {
-            throw new FileNotFoundException("Destination directory '" + destDir +
-                    "' does not exist [createDestDir=" + createDestDir + "]");
-        }
         if (!destDir.isDirectory()) {
-            throw new IOException("Destination '" + destDir + "' is not a directory");
+            if (destDir.exists()) {
+                throw new IOException("Destination '" + destDir + "' is not a directory");
+            } else if (createDestDir) {
+                if (!destDir.mkdirs()) {
+                    throw new IOException("Could not create destination directories '" + destDir + "'");
+                }
+            } else {
+                throw new FileNotFoundException("Destination directory '" + destDir +
+                        "' does not exist [createDestDir=" + createDestDir + "]");
+            }
         }
         moveDirectory(src, new File(destDir, src.getName()));
     }