浏览代码

HADOOP-6009. S3N listStatus incorrectly returns null instead of empty array when called on empty root. Contributed by Ian Nowland.

git-svn-id: https://svn.apache.org/repos/asf/hadoop/common/trunk@812479 13f79535-47bb-0310-9956-ffa450edef68
Thomas White 16 年之前
父节点
当前提交
174b3e8a74

+ 3 - 0
CHANGES.txt

@@ -987,6 +987,9 @@ Trunk (unreleased changes)
     HADOOP-6243. Fix a NullPointerException in processing deprecated keys.
     (Sreekanth Ramakrishnan via yhemanth)
 
+    HADOOP-6009. S3N listStatus incorrectly returns null instead of empty
+    array when called on empty root. (Ian Nowland via tomwhite)
+
 Release 0.20.1 - Unreleased
 
   INCOMPATIBLE CHANGES

+ 1 - 0
src/java/org/apache/hadoop/fs/s3native/NativeS3FileSystem.java

@@ -455,6 +455,7 @@ public class NativeS3FileSystem extends FileSystem {
     } while (priorLastKey != null);
     
     if (status.isEmpty() &&
+        key.length() > 0 &&
         store.retrieveMetadata(key + FOLDER_SUFFIX) == null) {
       throw new FileNotFoundException("File " + f + " does not exist.");
     }

+ 4 - 1
src/test/core/org/apache/hadoop/fs/s3native/NativeS3FileSystemContractBaseTest.java

@@ -48,10 +48,13 @@ public abstract class NativeS3FileSystemContractBaseTest
   }
   
   public void testListStatusForRoot() throws Exception {
+    FileStatus[] paths = fs.listStatus(path("/"));
+    assertEquals(0, paths.length);
+    
     Path testDir = path("/test");
     assertTrue(fs.mkdirs(testDir));
     
-    FileStatus[] paths = fs.listStatus(path("/"));
+    paths = fs.listStatus(path("/"));
     assertEquals(1, paths.length);
     assertEquals(path("/test"), paths[0].getPath());
   }