You are viewing a plain text version of this content. The canonical link for it is here.
Posted to common-commits@hadoop.apache.org by vi...@apache.org on 2020/10/23 06:16:26 UTC
[hadoop] branch branch-3.3 updated: HADOOP-17306.
RawLocalFileSystem's lastModifiedTime() looses milli seconds in JDK <
10.b09 (#2387)
This is an automated email from the ASF dual-hosted git repository.
vinayakumarb pushed a commit to branch branch-3.3
in repository https://gitbox.apache.org/repos/asf/hadoop.git
The following commit(s) were added to refs/heads/branch-3.3 by this push:
new e21b812 HADOOP-17306. RawLocalFileSystem's lastModifiedTime() looses milli seconds in JDK < 10.b09 (#2387)
e21b812 is described below
commit e21b81276e04138301dae1aa88da7bc4a51722fd
Author: Vinayakumar B <vi...@apache.org>
AuthorDate: Fri Oct 23 11:30:02 2020 +0530
HADOOP-17306. RawLocalFileSystem's lastModifiedTime() looses milli seconds in JDK < 10.b09 (#2387)
---
.../org/apache/hadoop/fs/RawLocalFileSystem.java | 11 +++++++---
.../hadoop/fs/TestRawLocalFileSystemContract.java | 24 ++++++++++++++++++++++
2 files changed, 32 insertions(+), 3 deletions(-)
diff --git a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
index 72eeb99..1294096 100644
--- a/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
+++ b/hadoop-common-project/hadoop-common/src/main/java/org/apache/hadoop/fs/RawLocalFileSystem.java
@@ -72,7 +72,12 @@ public class RawLocalFileSystem extends FileSystem {
public static void useStatIfAvailable() {
useDeprecatedFileStatus = !Stat.isAvailable();
}
-
+
+ @VisibleForTesting
+ static void setUseDeprecatedFileStatus(boolean useDeprecatedFileStatus) {
+ RawLocalFileSystem.useDeprecatedFileStatus = useDeprecatedFileStatus;
+ }
+
public RawLocalFileSystem() {
workingDir = getInitialWorkingDirectory();
}
@@ -700,8 +705,8 @@ public class RawLocalFileSystem extends FileSystem {
DeprecatedRawLocalFileStatus(File f, long defaultBlockSize, FileSystem fs)
throws IOException {
super(f.length(), f.isDirectory(), 1, defaultBlockSize,
- f.lastModified(), getLastAccessTime(f),
- null, null, null,
+ Files.getLastModifiedTime(f.toPath()).toMillis(),
+ getLastAccessTime(f),null, null, null,
new Path(f.getPath()).makeQualified(fs.getUri(),
fs.getWorkingDirectory()));
}
diff --git a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestRawLocalFileSystemContract.java b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestRawLocalFileSystemContract.java
index b51419d..cb45c9e 100644
--- a/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestRawLocalFileSystemContract.java
+++ b/hadoop-common-project/hadoop-common/src/test/java/org/apache/hadoop/fs/TestRawLocalFileSystemContract.java
@@ -203,4 +203,28 @@ public class TestRawLocalFileSystemContract extends FileSystemContractBaseTest {
}
}
+ @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();
+ }
+ }
}
---------------------------------------------------------------------
To unsubscribe, e-mail: common-commits-unsubscribe@hadoop.apache.org
For additional commands, e-mail: common-commits-help@hadoop.apache.org