commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nia...@apache.org
Subject svn commit: r1002424 - in /commons/proper/io/trunk/src: java/org/apache/commons/io/FileUtils.java test/org/apache/commons/io/FileUtilsTestCase.java
Date Tue, 28 Sep 2010 23:54:26 GMT
Author: niallp
Date: Tue Sep 28 23:54:26 2010
New Revision: 1002424

URL: http://svn.apache.org/viewvc?rev=1002424&view=rev
Log:
IO-217 FileUtils.copyDirectoryToDirectory makes infinite loops - thanks to Roun Lee for the
patch

Modified:
    commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
    commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java

Modified: commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java?rev=1002424&r1=1002423&r2=1002424&view=diff
==============================================================================
--- commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java (original)
+++ commons/proper/io/trunk/src/java/org/apache/commons/io/FileUtils.java Tue Sep 28 23:54:26
2010
@@ -1019,6 +1019,11 @@ public class FileUtils {
      */
     private static void doCopyDirectory(File srcDir, File destDir, FileFilter filter,
             boolean preserveFileDate, List<String> exclusionList) throws IOException
{
+        // recurse
+        File[] files = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
+        if (files == null) {  // null if security restricted
+            throw new IOException("Failed to list contents of " + srcDir);
+        }
         if (destDir.exists()) {
             if (destDir.isDirectory() == false) {
                 throw new IOException("Destination '" + destDir + "' exists but is not a
directory");
@@ -1034,11 +1039,6 @@ public class FileUtils {
         if (destDir.canWrite() == false) {
             throw new IOException("Destination '" + destDir + "' cannot be written to");
         }
-        // recurse
-        File[] files = filter == null ? srcDir.listFiles() : srcDir.listFiles(filter);
-        if (files == null) {  // null if security restricted
-            throw new IOException("Failed to list contents of " + srcDir);
-        }
         for (File file : files) {
             File copiedFile = new File(destDir, file.getName());
             if (exclusionList == null || !exclusionList.contains(file.getCanonicalPath()))
{

Modified: commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java?rev=1002424&r1=1002423&r2=1002424&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/org/apache/commons/io/FileUtilsTestCase.java Tue Sep
28 23:54:26 2010
@@ -905,6 +905,14 @@ public class FileUtilsTestCase extends F
         assertEquals(expectedSize, FileUtils.sizeOfDirectory(grandParentDir));
     }
 
+    /** Test for IO-217 FileUtils.copyDirectoryToDirectory makes infinite loops */
+    public void testCopyDirectoryToItself() throws Exception {
+        File dir = new File(getTestDirectory(), "itself");
+        dir.mkdirs();
+        FileUtils.copyDirectoryToDirectory(dir, dir);
+        assertEquals(1, LIST_WALKER.list(dir).size());
+    }
+
     private void createFilesForTestCopyDirectory(File grandParentDir, File parentDir, File
childDir) throws Exception {
         File childDir2 = new File(parentDir, "child2");
         File grandChildDir = new File(childDir, "grandChild");



Mime
View raw message