From 01be4503c3b053d2cff0b179774dabfd267877db Mon Sep 17 00:00:00 2001 From: Kai Zheng Date: Mon, 13 Feb 2017 13:18:20 +0800 Subject: [PATCH] HADOOP-14069. AliyunOSS: listStatus returns wrong file info. Contributed by Fei Hui --- .../apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java | 2 +- .../fs/aliyun/oss/TestAliyunOSSFileSystemContract.java | 7 +++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java index 34263198da..0491087d02 100644 --- a/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java +++ b/hadoop-tools/hadoop-aliyun/src/main/java/org/apache/hadoop/fs/aliyun/oss/AliyunOSSFileSystem.java @@ -352,7 +352,7 @@ public FileStatus[] listStatus(Path path) throws IOException { if (LOG.isDebugEnabled()) { LOG.debug("Adding: rd: " + keyPath); } - result.add(new FileStatus(0, true, 1, 0, 0, keyPath)); + result.add(getFileStatus(keyPath)); } } diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java index ad8ef6ee3a..3ebf5077b7 100644 --- a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java +++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSFileSystemContract.java @@ -22,6 +22,7 @@ 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 void testGetFileStatusFileAndDirectory() throws Exception { 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 {