8191872: (fs) UnixNativeDispatcher conditionally compiles in support for high precision timestamps
Summary: Remove POSIX conditional compilation and correct stat64 times for macOS
Reviewed-by: alanb, simonis
--- a/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c Thu Dec 07 16:45:19 2017 +0000
+++ b/src/java.base/unix/native/libnio/fs/UnixNativeDispatcher.c Thu Dec 07 08:56:04 2017 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2008, 2016, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2008, 2017, Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -476,10 +476,14 @@
(*env)->SetLongField(env, attrs, attrs_st_birthtime_sec, (jlong)buf->st_birthtime);
#endif
-#if (_POSIX_C_SOURCE >= 200809L) || defined(__solaris__)
+#ifndef MACOSX
(*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->st_atim.tv_nsec);
(*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->st_mtim.tv_nsec);
(*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->st_ctim.tv_nsec);
+#else
+ (*env)->SetLongField(env, attrs, attrs_st_atime_nsec, (jlong)buf->st_atimespec.tv_nsec);
+ (*env)->SetLongField(env, attrs, attrs_st_mtime_nsec, (jlong)buf->st_mtimespec.tv_nsec);
+ (*env)->SetLongField(env, attrs, attrs_st_ctime_nsec, (jlong)buf->st_ctimespec.tv_nsec);
#endif
}
--- a/test/jdk/java/nio/file/Files/SetLastModifiedTime.java Thu Dec 07 16:45:19 2017 +0000
+++ b/test/jdk/java/nio/file/Files/SetLastModifiedTime.java Thu Dec 07 08:56:04 2017 -0800
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2014, Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2014, 2017 Oracle and/or its affiliates. All rights reserved.
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
*
* This code is free software; you can redistribute it and/or modify it
@@ -21,6 +21,7 @@
* questions.
*/
+import java.io.File;
import java.nio.file.Files;
import java.nio.file.Path;
import java.nio.file.Paths;
@@ -36,7 +37,7 @@
/**
* @test
- * @bug 4313887 8062949
+ * @bug 4313887 8062949 8191872
* @library ..
* @run testng SetLastModifiedTime
* @summary Unit test for Files.setLastModifiedTime
@@ -114,5 +115,20 @@
assertTrue(false);
} catch (NullPointerException expected) { }
}
+
+ @Test
+ public void testCompare() throws Exception {
+ Path path = Files.createFile(testDir.resolve("path"));
+ long timeMillis = 1512520600195L;
+ FileTime fileTime = FileTime.fromMillis(timeMillis);
+ Files.setLastModifiedTime(path, fileTime);
+ File file = path.toFile();
+ long ioTime = file.lastModified();
+ long nioTime = Files.getLastModifiedTime(path).toMillis();
+ assertTrue(ioTime == timeMillis || ioTime == 1000*(timeMillis/1000),
+ "File.lastModified() not in {time, 1000*(time/1000)}");
+ assertEquals(nioTime, ioTime,
+ "File.lastModified() != Files.getLastModifiedTime().toMillis()");
+ }
}