commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ggreg...@apache.org
Subject svn commit: r1326588 - in /commons/proper/io/trunk/src: changes/changes.xml main/java/org/apache/commons/io/FileUtils.java test/java/org/apache/commons/io/FileUtilsTestCase.java
Date Mon, 16 Apr 2012 13:03:17 GMT
Author: ggregory
Date: Mon Apr 16 13:03:17 2012
New Revision: 1326588

URL: http://svn.apache.org/viewvc?rev=1326588&view=rev
Log:
[IO-319] FileUtils.sizeOfDirectory follows symbolic links.

Modified:
    commons/proper/io/trunk/src/changes/changes.xml
    commons/proper/io/trunk/src/main/java/org/apache/commons/io/FileUtils.java
    commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.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=1326588&r1=1326587&r2=1326588&view=diff
==============================================================================
--- commons/proper/io/trunk/src/changes/changes.xml (original)
+++ commons/proper/io/trunk/src/changes/changes.xml Mon Apr 16 13:03:17 2012
@@ -46,6 +46,12 @@ The <action> type attribute can be add,u
 
   <body>
     <!-- The release date is the date RC is cut -->
+    <release version="2.4" date="2012-TDB-TDB" description="">
+      <action issue="IO-319" dev="ggregory" type="add" due-to="ggregory">
+        FileUtils.sizeOfDirectory follows symbolic links.
+      </action>            
+    </release>
+    <!-- The release date is the date RC is cut -->
     <release version="2.3" date="2012-April-10" description="">
       <action issue="IO-322" dev="ggregory" type="add" due-to="ggregory">
         Add and use class Charsets.

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=1326588&r1=1326587&r2=1326588&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 Mon Apr 16
13:03:17 2012
@@ -2354,12 +2354,20 @@ public class FileUtils {
 
         long size = 0;
 
-        File[] files = directory.listFiles();
+        final File[] files = directory.listFiles();
         if (files == null) {  // null if security restricted
             return 0L;
         }
-        for (File file : files) {
-            size += sizeOf(file);
+        for (final File file : files) {
+            boolean isSymLink;
+            try {
+                isSymLink = isSymlink(file);
+            } catch (IOException ioe) {
+                isSymLink = true;
+            }
+            if (!isSymLink) {
+                size += sizeOf(file);
+            }
         }
 
         return size;

Modified: commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java
URL: http://svn.apache.org/viewvc/commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java?rev=1326588&r1=1326587&r2=1326588&view=diff
==============================================================================
--- commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java (original)
+++ commons/proper/io/trunk/src/test/java/org/apache/commons/io/FileUtilsTestCase.java Mon
Apr 16 13:03:17 2012
@@ -711,6 +711,19 @@ public class FileUtilsTestCase extends F
         file.delete();
         file.mkdir();
 
+        // Create a cyclic symlink
+        if(!FilenameUtils.isSystemWindows()) {
+            Runtime.getRuntime()
+                .exec("ln -s " + file + "/.. " + file + "/cycle");
+        } else {
+            try {
+                Runtime.getRuntime()
+                    .exec("mklink /D " + file + "/cycle" + file + "/.. ");
+            } catch(IOException ioe) { // So that tests run in FAT filesystems
+              //don't fail
+            }
+        }
+
         assertEquals(
             "Unexpected directory size",
             TEST_DIRECTORY_SIZE,



Mime
View raw message