hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r1310018 - in /hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common: CHANGES.txt pom.xml src/main/java/org/apache/hadoop/fs/FileUtil.java src/test/java/org/apache/hadoop/fs/TestFileUtil.java
Date Thu, 05 Apr 2012 19:14:18 GMT
Author: bobby
Date: Thu Apr  5 19:14:17 2012
New Revision: 1310018

URL: http://svn.apache.org/viewvc?rev=1310018&view=rev
Log:
HADOOP-6963. In FileUtil.getDU(..), neither include the size of directories nor follow symbolic
links.  (Ravi Prakash via bobby)

Modified:
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/pom.xml
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
    hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1310018&r1=1310017&r2=1310018&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/CHANGES.txt Thu
Apr  5 19:14:17 2012
@@ -18,6 +18,9 @@ Release 0.23.3 - UNRELEASED
     HADOOP-8179. risk of NPE in CopyCommands processArguments() (Daryn Sharp
     via bobby)
 
+    HADOOP-6963. In FileUtil.getDU(..), neither include the size of directories
+    nor follow symbolic links.  (Ravi Prakash via bobby)
+
 Release 0.23.2 - UNRELEASED 
 
   NEW FEATURES

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/pom.xml
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/pom.xml?rev=1310018&r1=1310017&r2=1310018&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/pom.xml (original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/pom.xml Thu Apr
 5 19:14:17 2012
@@ -78,6 +78,11 @@
       <scope>compile</scope>
     </dependency>
     <dependency>
+      <groupId>commons-io</groupId>
+      <artifactId>commons-io</artifactId>
+      <scope>compile</scope>
+    </dependency>
+    <dependency>
       <groupId>javax.servlet</groupId>
       <artifactId>servlet-api</artifactId>
       <scope>compile</scope>

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java?rev=1310018&r1=1310017&r2=1310018&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/FileUtil.java
Thu Apr  5 19:14:17 2012
@@ -483,11 +483,18 @@ public class FileUtil {
     if (!dir.isDirectory()) {
       return dir.length();
     } else {
-      size = dir.length();
       File[] allFiles = dir.listFiles();
       if(allFiles != null) {
          for (int i = 0; i < allFiles.length; i++) {
-            size = size + getDU(allFiles[i]);
+           boolean isSymLink;
+           try {
+             isSymLink = org.apache.commons.io.FileUtils.isSymlink(allFiles[i]);
+           } catch(IOException ioe) {
+             isSymLink = true;
+           }
+           if(!isSymLink) {
+             size += getDU(allFiles[i]);
+           }
          }
       }
       return size;

Modified: hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java?rev=1310018&r1=1310017&r2=1310018&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
(original)
+++ hadoop/common/branches/branch-0.23/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFileUtil.java
Thu Apr  5 19:14:17 2012
@@ -93,6 +93,9 @@ public class TestFileUtil {
     // create files in partitioned directories
     createFile(partitioned, "part-r-00000", "foo");
     createFile(partitioned, "part-r-00001", "bar");
+
+    // create a cycle using symlinks. Cycles should be handled
+    FileUtil.symLink(del.toString(), dir1.toString() + "/cycle");
   }
 
   /**
@@ -458,4 +461,18 @@ public class TestFileUtil {
 
     return result;
   }
+
+  /**
+   * Test that getDU is able to handle cycles caused due to symbolic links
+   * and that directory sizes are not added to the final calculated size
+   * @throws IOException
+   */
+  @Test
+  public void testGetDU() throws IOException {
+    setupDirs();
+
+    long du = FileUtil.getDU(TEST_DIR);
+    //Only two files (in partitioned) have 4 bytes each
+    Assert.assertEquals(du, 8);
+  }
 }



Mime
View raw message