hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rang...@apache.org
Subject svn commit: r627880 - in /hadoop/core/trunk: CHANGES.txt src/java/org/apache/hadoop/fs/FsShell.java src/test/org/apache/hadoop/dfs/TestDFSShell.java
Date Thu, 14 Feb 2008 21:43:15 GMT
Author: rangadi
Date: Thu Feb 14 13:43:12 2008
New Revision: 627880

URL: http://svn.apache.org/viewvc?rev=627880&view=rev
Log:
HADOOP-2195. '-mkdir' behaviour is now closer to Linux shell in case of
             errors. (Mahadev Konar via rangadi)

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=627880&r1=627879&r2=627880&view=diff
==============================================================================
--- hadoop/core/trunk/CHANGES.txt (original)
+++ hadoop/core/trunk/CHANGES.txt Thu Feb 14 13:43:12 2008
@@ -18,6 +18,9 @@
 
   BUG FIXES
 
+    HADOOP-2195. '-mkdir' behaviour is now closer to Linux shell in case of
+                 errors. (Mahadev Konar via rangadi)
+    
     HADOOP-2190. bring behaviour '-ls' and '-du' closer to Linux shell 
                  commands in case of errors. (Mahadev Konar via rangadi)
     

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=627880&r1=627879&r2=627880&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 14 13:43:12 2008
@@ -673,8 +673,21 @@
   void mkdir(String src) throws IOException {
     Path f = new Path(src);
     FileSystem srcFs = f.getFileSystem(getConf());
-    if (!srcFs.mkdirs(f)) {
-      throw new IOException("Mkdirs failed to create " + src);
+    FileStatus fstatus = null;
+    try {
+      fstatus = srcFs.getFileStatus(f);
+      if (fstatus.isDir()) {
+        throw new IOException("cannot create directory " 
+            + src + ": File exists");
+      }
+      else {
+        throw new IOException(src + " exists but " +
+            "is not a directory");
+      }
+    } catch(FileNotFoundException e) {
+        if (!srcFs.mkdirs(f)) {
+          throw new IOException("failed to create " + src);
+        }
     }
   }
 

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=627880&r1=627879&r2=627880&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 14 13:43:12
2008
@@ -255,6 +255,27 @@
       ret = ToolRunner.run(shell, argv);
       assertTrue(" -ls on nonexistent glob returns -1",
           (ret < 0));
+      out.reset();
+      argv[0] = "-mkdir";
+      argv[1] = "/testdir";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue(" -mkdir returned -1 ", (ret < 0));
+      assertTrue(" -mkdir returned File exists", 
+          (returned.lastIndexOf("File exists") != -1));
+      Path testFile = new Path("/testfile");
+      OutputStream outtmp = srcFs.create(testFile);
+      outtmp.write(testFile.toString().getBytes());
+      outtmp.close();
+      out.reset();
+      argv[0] = "-mkdir";
+      argv[1] = "/testfile";
+      ret = ToolRunner.run(shell, argv);
+      returned = out.toString();
+      assertTrue(" -mkdir returned -1", (ret < 0));
+      assertTrue(" -mkdir returned this is a file ",
+          (returned.lastIndexOf("not a directory") != -1));
+      out.reset();
     } finally {
       if (bak != null) {
         System.setErr(bak);



Mime
View raw message