hadoop-common-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bo...@apache.org
Subject svn commit: r1301622 - in /hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common: ./ src/main/java/org/apache/hadoop/fs/shell/ src/test/java/org/apache/hadoop/fs/
Date Fri, 16 Mar 2012 16:10:21 GMT
Author: bobby
Date: Fri Mar 16 16:10:20 2012
New Revision: 1301622

URL: http://svn.apache.org/viewvc?rev=1301622&view=rev
Log:
svn merge -c 1301612 from trunk to branch-0.23.2 FIXES HADOOP-8176.  Disambiguate the destination
of FsShell copies (Daryn Sharp via bobby)

Modified:
    hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/CHANGES.txt
    hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
    hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java
    hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java

Modified: hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/CHANGES.txt?rev=1301622&r1=1301621&r2=1301622&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/CHANGES.txt Fri
Mar 16 16:10:20 2012
@@ -94,6 +94,9 @@ Release 0.23.2 - UNRELEASED
 
     HADOOP-8175. Add -p option to mkdir in FsShell.  (Daryn Sharp via szetszwo)
 
+    HADOOP-8176.  Disambiguate the destination of FsShell copies (Daryn Sharp
+    via bobby)
+
 Release 0.23.1 - 2012-02-17 
 
   INCOMPATIBLE CHANGES

Modified: hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java?rev=1301622&r1=1301621&r2=1301622&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
(original)
+++ hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/CommandWithDestination.java
Fri Mar 16 16:10:20 2012
@@ -200,6 +200,8 @@ abstract class CommandWithDestination ex
     // a child path if dst is a dir; after recursion, it's always a dir
     if ((getDepth() > 0) || (dst.exists && dst.stat.isDirectory())) {
       target = dst.getPathDataForChild(src);
+    } else if (dst.representsDirectory()) { // see if path looks like a dir
+      target = dst.getPathDataForChild(src);
     } else {
       target = dst;
     }

Modified: hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java?rev=1301622&r1=1301621&r2=1301622&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java
(original)
+++ hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/shell/PathData.java
Fri Mar 16 16:10:20 2012
@@ -188,12 +188,21 @@ public class PathData implements Compara
    * @throws IOException upon unexpected error
    */
   public boolean parentExists() throws IOException {
+    return representsDirectory()
+        ? fs.exists(path) : fs.exists(path.getParent());
+  }
+
+  /**
+   * Check if the path represents a directory as determined by the basename
+   * being "." or "..", or the path ending with a directory separator 
+   * @return boolean if this represents a directory
+   */
+  public boolean representsDirectory() {
     String uriPath = uri.getPath();
     String name = uriPath.substring(uriPath.lastIndexOf("/")+1);
     // Path will munch off the chars that indicate a dir, so there's no way
     // to perform this test except by examining the raw basename we maintain
-    return (name.isEmpty() || name.equals(".") || name.equals(".."))
-        ? fs.exists(path) : fs.exists(path.getParent());
+    return (name.isEmpty() || name.equals(".") || name.equals(".."));
   }
   
   /**

Modified: hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java?rev=1301622&r1=1301621&r2=1301622&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java
(original)
+++ hadoop/common/branches/branch-0.23.2/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestFsShellCopy.java
Fri Mar 16 16:10:20 2012
@@ -226,6 +226,54 @@ public class TestFsShellCopy {  
   }
   
   @Test
+  public void testRepresentsDir() throws Exception {
+    Path subdirDstPath = new Path(dstPath, srcPath.getName());
+    String argv[] = null;
+    lfs.delete(dstPath, true);
+    assertFalse(lfs.exists(dstPath));
+
+    argv = new String[]{ "-put", srcPath.toString(), dstPath.toString() };
+    assertEquals(0, shell.run(argv));
+    assertTrue(lfs.exists(dstPath) && lfs.isFile(dstPath));
+
+    lfs.delete(dstPath, true);
+    assertFalse(lfs.exists(dstPath));
+
+    // since dst path looks like a dir, it should not copy the file and
+    // rename it to what looks like a directory
+    lfs.delete(dstPath, true); // make copy fail
+    for (String suffix : new String[]{ "/", "/." } ) {
+      argv = new String[]{
+          "-put", srcPath.toString(), dstPath.toString()+suffix };
+      assertEquals(1, shell.run(argv));
+      assertFalse(lfs.exists(dstPath));
+      assertFalse(lfs.exists(subdirDstPath));
+    }
+
+    // since dst path looks like a dir, it should not copy the file and
+    // rename it to what looks like a directory
+    for (String suffix : new String[]{ "/", "/." } ) {
+      // empty out the directory and create to make copy succeed
+      lfs.delete(dstPath, true);
+      lfs.mkdirs(dstPath);
+      argv = new String[]{
+          "-put", srcPath.toString(), dstPath.toString()+suffix };
+      assertEquals(0, shell.run(argv));
+      assertTrue(lfs.exists(subdirDstPath));
+      assertTrue(lfs.isFile(subdirDstPath));
+    }
+
+    // ensure .. is interpreted as a dir
+    String dotdotDst = dstPath+"/foo/..";
+    lfs.delete(dstPath, true);
+    lfs.mkdirs(new Path(dstPath, "foo"));
+    argv = new String[]{ "-put", srcPath.toString(), dotdotDst };
+    assertEquals(0, shell.run(argv));
+    assertTrue(lfs.exists(subdirDstPath));
+    assertTrue(lfs.isFile(subdirDstPath));
+  }
+  
+  @Test
   public void testCopyMerge() throws Exception {
     Path root = new Path(testRootDir, "TestMerge");
     Path f1 = new Path(root, "f1");



Mime
View raw message