You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by cu...@apache.org on 2007/01/26 22:21:01 UTC
svn commit: r500354 - in /lucene/hadoop/trunk: CHANGES.txt
src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
src/java/org/apache/hadoop/fs/FileSystem.java
src/java/org/apache/hadoop/fs/FsShell.java
Author: cutting
Date: Fri Jan 26 13:21:00 2007
New Revision: 500354
URL: http://svn.apache.org/viewvc?view=rev&rev=500354
Log:
HADOOP-909. Fix the 'du' command to correctly compute the size of FileSystem directory trees. Contributed by Hairong.
Modified:
lucene/hadoop/trunk/CHANGES.txt
lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java
Modified: lucene/hadoop/trunk/CHANGES.txt
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/CHANGES.txt?view=diff&rev=500354&r1=500353&r2=500354
==============================================================================
--- lucene/hadoop/trunk/CHANGES.txt (original)
+++ lucene/hadoop/trunk/CHANGES.txt Fri Jan 26 13:21:00 2007
@@ -60,6 +60,9 @@
18. HADOOP-912. Fix a bug in TaskTracker.isIdle() that was
sporadically causing unit test failures. (Arun C Murthy via cutting)
+19. HADOOP-909. Fix the 'du' command to correctly compute the size of
+ FileSystem directory trees. (Hairong Kuang via cutting)
+
Release 0.10.1 - 2007-01-10
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java?view=diff&rev=500354&r1=500353&r2=500354
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java Fri Jan 26 13:21:00 2007
@@ -176,6 +176,15 @@
return (info == null) ? 0 : info[0].getLen();
}
+ public long getContentLength(Path f) throws IOException {
+ if (f instanceof DfsPath) {
+ return ((DfsPath)f).getContentsLength();
+ }
+
+ DFSFileInfo info[] = dfs.listPaths(getPath(f));
+ return (info == null) ? 0 : info[0].getContentsLen();
+ }
+
public short getReplication(Path f) throws IOException {
if (f instanceof DfsPath) {
return ((DfsPath)f).getReplication();
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java?view=diff&rev=500354&r1=500353&r2=500354
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FileSystem.java Fri Jan 26 13:21:00 2007
@@ -534,6 +534,25 @@
/** The number of bytes in a file. */
public abstract long getLength(Path f) throws IOException;
+
+ /** Return the number of bytes of the given path
+ * If <i>f</i> is a file, return the size of the file;
+ * If <i>f</i> is a directory, return the size of the directory tree
+ */
+ public long getContentLength(Path f) throws IOException {
+ if (!isDirectory(f)) {
+ // f is a file
+ return getLength(f);
+ }
+
+ // f is a diretory
+ Path[] contents = listPathsRaw(f);
+ long size = 0;
+ for(int i=0; i<contents.length; i++) {
+ size += getContentLength(contents[i]);
+ }
+ return size;
+ }
final private static PathFilter DEFAULT_FILTER = new PathFilter() {
public boolean accept(Path file) {
Modified: lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java
URL: http://svn.apache.org/viewvc/lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java?view=diff&rev=500354&r1=500353&r2=500354
==============================================================================
--- lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ lucene/hadoop/trunk/src/java/org/apache/hadoop/fs/FsShell.java Fri Jan 26 13:21:00 2007
@@ -352,7 +352,7 @@
System.out.println("Found " + items.length + " items");
for (int i = 0; i < items.length; i++) {
Path cur = items[i];
- System.out.println(cur + "\t" + fs.getLength(cur));
+ System.out.println(cur + "\t" + fs.getContentLength(cur));
}
}
}
@@ -374,7 +374,7 @@
if (items != null) {
int totalSize=0;
for(int j=0; j<items.length; j++) {
- totalSize += fs.getLength(items[j]);
+ totalSize += fs.getContentLength(items[j]);
}
String pathStr = paths[i].toString();
System.out.println(