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 3b266c8393..34263198da 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 @@ -218,7 +218,8 @@ public FileStatus getFileStatus(Path path) throws IOException { throw new FileNotFoundException(path + ": No such file or directory!"); } } else if (objectRepresentsDirectory(key, meta.getContentLength())) { - return new FileStatus(0, true, 1, 0, 0, qualifiedPath); + return new FileStatus(0, true, 1, 0, meta.getLastModified().getTime(), + qualifiedPath); } else { return new FileStatus(meta.getContentLength(), false, 1, getDefaultBlockSize(path), meta.getLastModified().getTime(), diff --git a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSInputStream.java b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSInputStream.java index 37af28ff06..10c4edda04 100644 --- a/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSInputStream.java +++ b/hadoop-tools/hadoop-aliyun/src/test/java/org/apache/hadoop/fs/aliyun/oss/TestAliyunOSSInputStream.java @@ -24,6 +24,7 @@ import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.contract.ContractTestUtils; import org.apache.hadoop.io.IOUtils; +import org.apache.hadoop.fs.FileStatus; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -142,4 +143,12 @@ public void testReadFile() throws Exception { assertTrue(instream.available() == 0); IOUtils.closeStream(instream); } + @Test + public void testDirectoryModifiedTime() throws Exception { + Path emptyDirPath = setPath("/test/emptyDirectory"); + fs.mkdirs(emptyDirPath); + FileStatus dirFileStatus = fs.getFileStatus(emptyDirPath); + assertTrue("expected the empty dir is new", + dirFileStatus.getModificationTime() > 0L); + } }