Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

svn merge -c 1310039 from branch-1 for HADOOP-6963.

  • Loading branch information...
commit 534d7c5ffb878f85c2948a3bbac140996bbafafe 1 parent 39e60d7
Tsz-wo Sze authored
3  CHANGES.txt
View
@@ -28,6 +28,9 @@ Release 1.0.3 - unreleased
HADOOP-5528. Ensure BinaryPartitioner is present in mapred libs. (Klaas
Bosteels via acmurthy)
+ HADOOP-6963. In FileUtil.getDU(..), neither include the size of directories
+ nor follow symbolic links. (Ravi Prakash via szetszwo)
+
Release 1.0.2 - 2012.03.24
NEW FEATURES
5 ivy.xml
View
@@ -85,6 +85,11 @@
rev="${commons-cli.version}"
conf="client->default"/>
+ <dependency org="commons-io"
+ name="commons-io"
+ rev="${commons-io.version}"
+ conf="client->default"/>
+
<dependency org="checkstyle"
name="checkstyle"
rev="${checkstyle.version}"
2  ivy/libraries.properties
View
@@ -38,7 +38,7 @@ commons-logging-api.version=1.0.4
commons-math.version=2.1
commons-el.version=1.0
commons-fileupload.version=1.2
-commons-io.version=1.4
+commons-io.version=2.1
commons-net.version=1.4.1
core.version=3.1.1
coreplugin.version=1.3.2
11 src/core/org/apache/hadoop/fs/FileUtil.java
View
@@ -448,11 +448,18 @@ public static long getDU(File dir) {
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;
16 src/test/org/apache/hadoop/fs/TestFileUtil.java
View
@@ -78,6 +78,9 @@ private void setupDirs() throws IOException {
File linkDir = new File(del, "tmpDir");
FileUtil.symLink(tmp.toString(), linkDir.toString());
Assert.assertEquals(5, del.listFiles().length);
+
+ // create a cycle using symlinks. Cycles should be handled
+ FileUtil.symLink(del.toString(), del.toString() + "/" + DIR + "1/cycle");
}
@After
@@ -303,4 +306,17 @@ public void testListAPI() throws IOException {
//Expected an IOException
}
}
+
+ /**
+ * 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);
+ Assert.assertEquals(du, 0);
+ }
}
Please sign in to comment.
Something went wrong with that request. Please try again.