Selaa lähdekoodia

svn merge -c 1101132 from trunk for HADOOP-7265.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/branches/yahoo-merge@1127275 13f79535-47bb-0310-9956-ffa450edef68
Tsz-wo Sze 14 vuotta sitten
vanhempi
commit
344f414b22

+ 3 - 0
CHANGES.txt

@@ -53,6 +53,9 @@ Trunk (unreleased changes)
     HADOOP-7251. Refactor the getmerge command to conform to new FsCommand
     class.  (Daryn Sharp via szetszwo)
 
+    HADOOP-7265. Keep track of relative paths in PathData.  (Daryn Sharp
+    via szetszwo)
+
   OPTIMIZATIONS
 
   BUG FIXES

+ 5 - 1
src/java/org/apache/hadoop/fs/shell/PathData.java

@@ -146,7 +146,11 @@ public class PathData {
     FileStatus[] stats = fs.listStatus(path);
     PathData[] items = new PathData[stats.length];
     for (int i=0; i < stats.length; i++) {
-      items[i] = new PathData(fs, stats[i]);
+      // preserve relative paths
+      String basename = stats[i].getPath().getName();
+      String parent = string;
+      if (!parent.endsWith(Path.SEPARATOR)) parent += Path.SEPARATOR;
+      items[i] = new PathData(fs, parent + basename, stats[i]);
     }
     return items;
   }

+ 20 - 0
src/test/core/org/apache/hadoop/fs/shell/TestPathData.java

@@ -53,6 +53,26 @@ public class TestPathData {
     checkPathData();
   }
 
+  @Test
+  public void testUnqualifiedUriContents() throws Exception {
+    dirString = "/tmp";
+    item = new PathData(dirString, conf);
+    PathData[] items = item.getDirectoryContents();
+    for (PathData item : items) {
+      assertTrue(item.toString().startsWith(dirString));
+    }
+  }
+
+  @Test
+  public void testQualifiedUriContents() throws Exception {
+    dirString = "file:/tmp";
+    item = new PathData(dirString, conf);
+    PathData[] items = item.getDirectoryContents();
+    for (PathData item : items) {
+      assertTrue(item.toString().startsWith(dirString));
+    }
+  }
+
   @Test
   public void testWithStringAndConfForBuggyPath() throws Exception {
     dirString = "file:///tmp";