You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by sz...@apache.org on 2011/03/21 21:53:16 UTC

svn commit: r1083954 - in /hadoop/common/branches/branch-0.20-security: CHANGES.txt src/hdfs/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java src/test/org/apache/hadoop/hdfs/TestListPathServlet.java

Author: szetszwo
Date: Mon Mar 21 20:53:16 2011
New Revision: 1083954

URL: http://svn.apache.org/viewvc?rev=1083954&view=rev
Log:
HDFS-1750. ListPathsServlet should not use HdfsFileStatus.getLocalName() to get file name since it may return an empty string.

Modified:
    hadoop/common/branches/branch-0.20-security/CHANGES.txt
    hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java
    hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestListPathServlet.java

Modified: hadoop/common/branches/branch-0.20-security/CHANGES.txt
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/CHANGES.txt?rev=1083954&r1=1083953&r2=1083954&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/CHANGES.txt (original)
+++ hadoop/common/branches/branch-0.20-security/CHANGES.txt Mon Mar 21 20:53:16 2011
@@ -5,6 +5,9 @@ Release 0.20.204.0 - unreleased
     HDFS-1592. At Startup, Valid volumes required in FSDataset doesn't
     handle consistently with volumes tolerated. (Bharath Mundlapudi)
 
+    HDFS-1750. ListPathsServlet should not use HdfsFileStatus.getLocalName()
+    to get file name since it may return an empty string.  (szetszwo)
+
 Release 0.20.203.0 - unreleased
 
     HADOOP-7190. Add metrics v1 back for backwards compatibility. (omalley)

Modified: hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java?rev=1083954&r1=1083953&r2=1083954&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java (original)
+++ hadoop/common/branches/branch-0.20-security/src/hdfs/org/apache/hadoop/hdfs/server/namenode/ListPathsServlet.java Mon Mar 21 20:53:16 2011
@@ -60,10 +60,11 @@ public class ListPathsServlet extends Df
    * Node information includes path, modification, permission, owner and group.
    * For files, it also includes size, replication and block-size. 
    */
-  static void writeInfo(String parent, HdfsFileStatus i, XMLOutputter doc) throws IOException {
+  static void writeInfo(final Path fullpath, final HdfsFileStatus i,
+      final XMLOutputter doc) throws IOException {
     final SimpleDateFormat ldf = df.get();
     doc.startTag(i.isDir() ? "directory" : "file");
-    doc.attribute("path", i.getFullPath(new Path(parent)).toUri().getPath());
+    doc.attribute("path", fullpath.toUri().getPath());
     doc.attribute("modified", ldf.format(new Date(i.getModificationTime())));
     doc.attribute("accesstime", ldf.format(new Date(i.getAccessTime())));
     if (!i.isDir()) {
@@ -152,7 +153,7 @@ public class ListPathsServlet extends Df
 
           HdfsFileStatus base = nn.getFileInfo(path);
           if ((base != null) && base.isDir()) {
-            writeInfo(path, base, doc);
+            writeInfo(base.getFullPath(new Path(path)), base, doc);
           }
 
           Stack<String> pathstack = new Stack<String>();
@@ -173,7 +174,8 @@ public class ListPathsServlet extends Df
                 }
                 HdfsFileStatus[] listing = thisListing.getPartialListing();
                 for (HdfsFileStatus i : listing) {
-                  String localName = i.getLocalName();
+                  final Path fullpath = i.getFullPath(new Path(p));
+                  final String localName = fullpath.getName();
                   if (exclude.matcher(localName).matches()
                       || !filter.matcher(localName).matches()) {
                     continue;
@@ -181,7 +183,7 @@ public class ListPathsServlet extends Df
                   if (recur && i.isDir()) {
                     pathstack.push(new Path(p, localName).toUri().getPath());
                   }
-                  writeInfo(p, i, doc);
+                  writeInfo(fullpath, i, doc);
                 }
                 lastReturnedName = thisListing.getLastName();
               } while (thisListing.hasMore());

Modified: hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestListPathServlet.java
URL: http://svn.apache.org/viewvc/hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestListPathServlet.java?rev=1083954&r1=1083953&r2=1083954&view=diff
==============================================================================
--- hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestListPathServlet.java (original)
+++ hadoop/common/branches/branch-0.20-security/src/test/org/apache/hadoop/hdfs/TestListPathServlet.java Mon Mar 21 20:53:16 2011
@@ -91,12 +91,18 @@ public class TestListPathServlet {
     createFile("/a", 1);
     createFile("/b", 1);
     mkdirs("/dir");
+
+    checkFile(new Path("/a"));
+    checkFile(new Path("/b"));
     checkStatus("/");
 
     // A directory with files and directories
     createFile("/dir/.a.crc", 1);
     createFile("/dir/b", 1);
     mkdirs("/dir/dir1");
+    
+    checkFile(new Path("/dir/.a.crc"));
+    checkFile(new Path("/dir/b"));
     checkStatus("/dir");
 
     // Non existent path
@@ -158,4 +164,36 @@ public class TestListPathServlet {
           found);
     }
   }
+
+  private void checkFile(final Path f) throws IOException {
+    final Path hdfspath = fs.makeQualified(f);
+    final FileStatus hdfsstatus = fs.getFileStatus(hdfspath);
+    FileSystem.LOG.info("hdfspath=" + hdfspath);
+
+    final Path hftppath = hftpFs.makeQualified(f);
+    final FileStatus hftpstatus = hftpFs.getFileStatus(hftppath);
+    FileSystem.LOG.info("hftppath=" + hftppath);
+    
+    Assert.assertEquals(hdfspath.toUri().getPath(),
+        hdfsstatus.getPath().toUri().getPath());
+    checkFileStatus(hdfsstatus, hftpstatus);
+  }
+
+  private static void checkFileStatus(final FileStatus expected,
+      final FileStatus computed) {
+    Assert.assertEquals(expected.getPath().toUri().getPath(),
+        computed.getPath().toUri().getPath());
+
+// TODO: test will fail if the following is un-commented. 
+//    Assert.assertEquals(expected.getAccessTime(), computed.getAccessTime());
+//    Assert.assertEquals(expected.getModificationTime(),
+//        computed.getModificationTime());
+
+    Assert.assertEquals(expected.getBlockSize(), computed.getBlockSize());
+    Assert.assertEquals(expected.getGroup(), computed.getGroup());
+    Assert.assertEquals(expected.getLen(), computed.getLen());
+    Assert.assertEquals(expected.getOwner(), computed.getOwner());
+    Assert.assertEquals(expected.getPermission(), computed.getPermission());
+    Assert.assertEquals(expected.getReplication(), computed.getReplication());
+  }
 }