HADOOP-6963. In FileUtil.getDU(..), neither include the size of directories nor follow symbolic links. Contributed by Ravi Prakash
git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@1309994 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
4c908d0987
commit
bf5b508074
@ -324,6 +324,9 @@ Release 2.0.0 - UNRELEASED
|
|||||||
HADOOP-8243. Security support broken in CLI (manual) failover controller
|
HADOOP-8243. Security support broken in CLI (manual) failover controller
|
||||||
(todd)
|
(todd)
|
||||||
|
|
||||||
|
HADOOP-6963. In FileUtil.getDU(..), neither include the size of directories
|
||||||
|
nor follow symbolic links. (Ravi Prakash via szetszwo)
|
||||||
|
|
||||||
BREAKDOWN OF HADOOP-7454 SUBTASKS
|
BREAKDOWN OF HADOOP-7454 SUBTASKS
|
||||||
|
|
||||||
HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh)
|
HADOOP-7455. HA: Introduce HA Service Protocol Interface. (suresh)
|
||||||
|
@ -78,6 +78,11 @@
|
|||||||
<artifactId>commons-net</artifactId>
|
<artifactId>commons-net</artifactId>
|
||||||
<scope>compile</scope>
|
<scope>compile</scope>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
<dependency>
|
||||||
|
<groupId>commons-io</groupId>
|
||||||
|
<artifactId>commons-io</artifactId>
|
||||||
|
<scope>compile</scope>
|
||||||
|
</dependency>
|
||||||
<dependency>
|
<dependency>
|
||||||
<groupId>javax.servlet</groupId>
|
<groupId>javax.servlet</groupId>
|
||||||
<artifactId>servlet-api</artifactId>
|
<artifactId>servlet-api</artifactId>
|
||||||
|
@ -483,11 +483,18 @@ public static long getDU(File dir) {
|
|||||||
if (!dir.isDirectory()) {
|
if (!dir.isDirectory()) {
|
||||||
return dir.length();
|
return dir.length();
|
||||||
} else {
|
} else {
|
||||||
size = dir.length();
|
|
||||||
File[] allFiles = dir.listFiles();
|
File[] allFiles = dir.listFiles();
|
||||||
if(allFiles != null) {
|
if(allFiles != null) {
|
||||||
for (int i = 0; i < allFiles.length; i++) {
|
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;
|
return size;
|
||||||
|
@ -93,6 +93,9 @@ private void setupDirs() throws IOException {
|
|||||||
// create files in partitioned directories
|
// create files in partitioned directories
|
||||||
createFile(partitioned, "part-r-00000", "foo");
|
createFile(partitioned, "part-r-00000", "foo");
|
||||||
createFile(partitioned, "part-r-00001", "bar");
|
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 @@ private boolean copyMerge(String src, String dst)
|
|||||||
|
|
||||||
return result;
|
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);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user