HADOOP-17306. RawLocalFileSystem's lastModifiedTime() looses milli seconds in JDK < 10.b09 (#2387)

This commit is contained in:
Vinayakumar B 2020-10-23 11:30:02 +05:30
parent 02709cb054
commit e21b81276e
No known key found for this signature in database
GPG Key ID: E4EAD9C3D0215A71
2 changed files with 32 additions and 3 deletions

View File

@ -73,6 +73,11 @@ public static void useStatIfAvailable() {
useDeprecatedFileStatus = !Stat.isAvailable(); useDeprecatedFileStatus = !Stat.isAvailable();
} }
@VisibleForTesting
static void setUseDeprecatedFileStatus(boolean useDeprecatedFileStatus) {
RawLocalFileSystem.useDeprecatedFileStatus = useDeprecatedFileStatus;
}
public RawLocalFileSystem() { public RawLocalFileSystem() {
workingDir = getInitialWorkingDirectory(); workingDir = getInitialWorkingDirectory();
} }
@ -700,8 +705,8 @@ private static long getLastAccessTime(File f) throws IOException {
DeprecatedRawLocalFileStatus(File f, long defaultBlockSize, FileSystem fs) DeprecatedRawLocalFileStatus(File f, long defaultBlockSize, FileSystem fs)
throws IOException { throws IOException {
super(f.length(), f.isDirectory(), 1, defaultBlockSize, super(f.length(), f.isDirectory(), 1, defaultBlockSize,
f.lastModified(), getLastAccessTime(f), Files.getLastModifiedTime(f.toPath()).toMillis(),
null, null, null, getLastAccessTime(f),null, null, null,
new Path(f.getPath()).makeQualified(fs.getUri(), new Path(f.getPath()).makeQualified(fs.getUri(),
fs.getWorkingDirectory())); fs.getWorkingDirectory()));
} }

View File

@ -203,4 +203,28 @@ public void testPermission() throws Exception {
} }
} }
@Test
public void testMTimeAtime() throws IOException {
RawLocalFileSystem.setUseDeprecatedFileStatus(true);
try {
Path testDir = getTestBaseDir();
String testFilename = "testmtime";
Path path = new Path(testDir, testFilename);
Path file = new Path(path, "file");
fs.create(file);
long now = System.currentTimeMillis();
long mtime = (now % 1000 == 0) ? now + 1 : now;
long atime = (now % 1000 == 0) ? now + 2 : now;
fs.setTimes(file, mtime, atime);
FileStatus fileStatus = fs.getFileStatus(file);
if (!Shell.MAC) {
// HADOOP-17306 ; Skip MacOS because HFS+ does not support
// milliseconds for mtime.
assertEquals(mtime, fileStatus.getModificationTime());
}
assertEquals(atime, fileStatus.getAccessTime());
} finally {
RawLocalFileSystem.useStatIfAvailable();
}
}
} }