Author: dhruba
Date: Tue Feb 12 22:19:05 2008
New Revision: 627265
URL: http://svn.apache.org/viewvc?rev=627265&view=rev
Log:
HADOOP-2191. du and dus command on non-existent directory gives
appropriate error message. (Mahadev Konar via dhruba)
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java
hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java
Modified: hadoop/core/trunk/CHANGES.txt
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/CHANGES.txt?rev=627265&r1=627264&r2=627265&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Tue Feb 12 22:19:05 2008
@@ -32,6 +32,9 @@
HADOOP-1593. FsShell works with paths in non-default FileSystem.
(Mahadev Konar via dhruba)
+ HADOOP-2191. du and dus command on non-existent directory gives
+ appropriate error message. (Mahadev Konar via dhruba)
+
Release 0.16.1 - Unrelease
BUG FIXES
Modified: hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java?rev=627265&r1=627264&r2=627265&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java (original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/fs/FsShell.java Tue Feb 12
22:19:05 2008
@@ -616,8 +616,10 @@
Path srcPath = new Path(src);
FileSystem srcFs = srcPath.getFileSystem(getConf());
Path items[] = srcFs.listPaths(srcFs.globPaths(srcPath));
- if (items == null) {
- throw new IOException("Could not get listing for " + src);
+ if ((items == null) || ((items.length == 0) &&
+ (!srcFs.exists(srcPath)))){
+ throw new FileNotFoundException("Cannot access " + src
+ + ": No such file or directory.");
} else {
System.out.println("Found " + items.length + " items");
for (int i = 0; i < items.length; i++) {
@@ -637,18 +639,20 @@
void dus(String src) throws IOException {
Path srcPath = new Path(src);
FileSystem srcFs = srcPath.getFileSystem(getConf());
- Path paths[] = srcFs.globPaths(new Path(src));
- if (paths==null || paths.length==0) {
- throw new IOException("dus: No match: " + src);
+ FileStatus status[] = srcFs.globStatus(new Path(src));
+ if (status==null || status.length==0) {
+ throw new FileNotFoundException("Cannot access " + src +
+ ": No such file or directory.");
}
- for(int i=0; i<paths.length; i++) {
- Path items[] = srcFs.listPaths(paths[i]);
+ for(int i=0; i<status.length; i++) {
+ FileStatus items[] = srcFs.listStatus(status[i].getPath());
if (items != null) {
long totalSize=0;
for(int j=0; j<items.length; j++) {
- totalSize += srcFs.getContentLength(items[j]);
+ totalSize += srcFs.getContentLength(
+ items[j].getPath());
}
- String pathStr = paths[i].toString();
+ String pathStr = status[i].getPath().toString();
System.out.println(
("".equals(pathStr)?".":pathStr) + "\t" +
totalSize);
}
Modified: hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java?rev=627265&r1=627264&r2=627265&view=diff
==============================================================================
--- hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java
(original)
+++ hadoop/core/trunk/src/test/org/apache/hadoop/dfs/TestDFSShell.java Tue Feb
12 22:19:05 2008
@@ -213,6 +213,21 @@
returned = out.toString();
assertTrue("rmr prints reasonable error ",
(returned.lastIndexOf("No such file or directory") != -1));
+ out.reset();
+ argv[0] = "-du";
+ argv[1] = "/nonexistentfile";
+ ret = ToolRunner.run(shell, argv);
+ returned = out.toString();
+ assertTrue(" -du prints reasonable error ",
+ (returned.lastIndexOf("No such file or directory") != -1));
+ out.reset();
+ argv[0] = "-dus";
+ argv[1] = "/nonexistentfile";
+ ret = ToolRunner.run(shell, argv);
+ returned = out.toString();
+ assertTrue(" -dus prints reasonable error",
+ (returned.lastIndexOf("No such file or directory") != -1));
+ out.reset();
} finally {
if (bak != null) {
System.setErr(bak);