Author: dhruba
Date: Thu Feb 7 06:47:54 2008
New Revision: 619430
URL: http://svn.apache.org/viewvc?rev=619430&view=rev
Log:
HADOOP-2194. dfs cat on a non-existent file throws FileNotFoundException.
(Mahadev Konar via dhruba)
Modified:
hadoop/core/trunk/CHANGES.txt
hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
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=619430&r1=619429&r2=619430&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu Feb 7 06:47:54 2008
@@ -26,6 +26,9 @@
HADOOP-1188. fstime file is updated when a storage directory containing
namespace image becomes inaccessible. (shv)
+ HADOOP-2194. dfs cat on a non-existent file throws FileNotFoundException.
+ (Mahadev Konar via dhruba)
+
Release 0.16.0 - 2008-02-07
INCOMPATIBLE CHANGES
Modified:
hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
URL:
http://svn.apache.org/viewvc/hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java?rev=619430&r1=619429&r2=619430&view=diff
==============================================================================
--- hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
(original)
+++ hadoop/core/trunk/src/java/org/apache/hadoop/dfs/DistributedFileSystem.java
Thu Feb 7 06:47:54 2008
@@ -112,7 +112,19 @@
}
public FSDataInputStream open(Path f, int bufferSize) throws IOException {
- return new
DFSClient.DFSDataInputStream(dfs.open(getPathName(f),bufferSize));
+ try {
+ return new
DFSClient.DFSDataInputStream(dfs.open(getPathName(f),bufferSize));
+ } catch(RemoteException e) {
+ if (IOException.class.getName().equals(e.getClassName()) &&
+ e.getMessage().startsWith(
+ "java.io.IOException: Cannot open filename")) {
+ // non-existent path
+ FileNotFoundException ne = new FileNotFoundException("File " + f + "
does not exist.");
+ throw (FileNotFoundException) ne.initCause(e);
+ } else {
+ throw e; // unexpected exception
+ }
+ }
}
public FSDataOutputStream create(Path f, FsPermission permission,
@@ -338,7 +350,8 @@
e.getMessage().startsWith(
"java.io.IOException: File does not exist: ")) {
// non-existent path
- throw new FileNotFoundException("File " + f + " does not exist.");
+ FileNotFoundException fe = new FileNotFoundException("File " + f + "
does not exist.");
+ throw (FileNotFoundException) fe.initCause(e);
} else {
throw e; // unexpected exception
}
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=619430&r1=619429&r2=619430&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 Thu Feb 7
06:47:54 2008
@@ -300,7 +300,7 @@
new DelayedExceptionThrowing() {
@Override
void process(Path p) throws IOException {
- if (fs.isDirectory(p)) {
+ if (fs.getFileStatus(p).isDir()) {
throw new IOException("Source must be a file.");
}
printToStdout(fs.open(p));
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=619430&r1=619429&r2=619430&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 Thu Feb
7 06:47:54 2008
@@ -174,6 +174,37 @@
}
}
+
+ /** check if we have any exceptions in cat command output */
+ public void testCatException() throws Exception {
+ Configuration conf = new Configuration();
+ MiniDFSCluster cluster = null;
+ PrintStream bak = null;
+ try {
+ cluster = new MiniDFSCluster(conf, 2, true, null);
+ Path root = new Path("/nonexistentfile");
+ bak = System.err;
+ ByteArrayOutputStream out = new ByteArrayOutputStream();
+ PrintStream tmp = new PrintStream(out);
+ System.setErr(tmp);
+ String[] argv = new String[2];
+ argv[0] = "-cat";
+ argv[1] = root.toUri().getPath();
+ int ret = ToolRunner.run(new FsShell(), argv);
+ assertTrue(" -cat returned -1 ", 0>=ret);
+ String returned = out.toString();
+ assertTrue("cat does not print exceptions ",
+ (returned.lastIndexOf("Exception") == -1));
+ } finally {
+ if (bak != null) {
+ System.setErr(bak);
+ }
+ if (cluster != null) {
+ cluster.shutdown();
+ }
+ }
+ }
+
public void testText() throws Exception {
Configuration conf = new Configuration();
MiniDFSCluster cluster = null;