Browse Source

HADOOP-14069. AliyunOSS: listStatus returns wrong file info. Contributed by Fei Hui

Kai Zheng 8 years ago
parent
commit
01be4503c3

+ 1 - 1
hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java

@@ -352,7 +352,7 @@ public class AliyunOSSFileSystem extends FileSystem {
             if (LOG.isDebugEnabled()) {
               LOG.debug("Adding: rd: " + keyPath);
             }
-            result.add(new FileStatus(0, true, 1, 0, 0, keyPath));
+            result.add(getFileStatus(keyPath));
           }
         }
 

+ 7 - 0
hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java

@@ -22,6 +22,7 @@ import org.apache.hadoop.conf.Configuration;
 import org.apache.hadoop.fs.FileAlreadyExistsException;
 import org.apache.hadoop.fs.FileSystemContractBaseTest;
 import org.apache.hadoop.fs.Path;
+import org.apache.hadoop.fs.FileStatus;
 
 import java.io.FileNotFoundException;
 import java.io.IOException;
@@ -206,6 +207,12 @@ public class TestAliyunOSSFileSystemContract
     assertTrue("Should be directory",
         this.fs.getFileStatus(dirPath).isDirectory());
     assertFalse("Should not be file", this.fs.getFileStatus(dirPath).isFile());
+
+    Path parentPath = this.path("/test/oss");
+    for (FileStatus fileStatus: fs.listStatus(parentPath)) {
+      assertTrue("file and directory should be new",
+          fileStatus.getModificationTime() > 0L);
+    }
   }
 
   public void testMkdirsForExistingFile() throws Exception {