HADOOP-14065. AliyunOSS: oss directory filestatus should use meta time. Contributed by Fei Hui

This commit is contained in:
Kai Zheng 2017-02-09 18:00:22 +08:00
parent 37b4acf7ce
commit a8a594b4c8
2 changed files with 11 additions and 1 deletions

View File

@ -218,7 +218,8 @@ public FileStatus getFileStatus(Path path) throws IOException {
throw new FileNotFoundException(path + ": No such file or directory!"); throw new FileNotFoundException(path + ": No such file or directory!");
} }
} else if (objectRepresentsDirectory(key, meta.getContentLength())) { } 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 { } else {
return new FileStatus(meta.getContentLength(), false, 1, return new FileStatus(meta.getContentLength(), false, 1,
getDefaultBlockSize(path), meta.getLastModified().getTime(), getDefaultBlockSize(path), meta.getLastModified().getTime(),

View File

@ -24,6 +24,7 @@
import org.apache.hadoop.fs.Path; import org.apache.hadoop.fs.Path;
import org.apache.hadoop.fs.contract.ContractTestUtils; import org.apache.hadoop.fs.contract.ContractTestUtils;
import org.apache.hadoop.io.IOUtils; import org.apache.hadoop.io.IOUtils;
import org.apache.hadoop.fs.FileStatus;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule; import org.junit.Rule;
@ -142,4 +143,12 @@ public void testReadFile() throws Exception {
assertTrue(instream.available() == 0); assertTrue(instream.available() == 0);
IOUtils.closeStream(instream); 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);
}
} }