8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps

Brian Burkhalter brian.burkhalter at oracle.com
Thu Jul 18 15:59:35 UTC 2019


> On Jul 18, 2019, at 7:08 AM, Alan Bateman <Alan.Bateman at oracle.com> wrote:
> 
> On 10/07/2019 21:39, Brian Burkhalter wrote:
>> https://bugs.openjdk.java.net/browse/JDK-8181493 <https://bugs.openjdk.java.net/browse/JDK-8181493>
>> http://cr.openjdk.java.net/~bpb/8181493/webrev.00/ <http://cr.openjdk.java.net/~bpb/8181493/webrev.00/>
>> 
>> This patch would change:
>> 
>> 1) UnixFileAttributeViews.setTimes() to set the access and modification times of a file or directory with nanosecond precision if the system call futimens() [1] is available, and
>> 2) UnixFileAttributes to initialize the creation, last access, and last modifications FileTimes with nanosecond precision.
>> 
>> New methods to support setting the nanosecond resolution access and modification times using futimens() are added to UnixNativeDispatcher. Note that unlike futimes() and lutimes(), futimens() is *not* guaranteed to be present for the _ALLBDS_SOURCE case and so it is looked up using dlsym().
> The implementation changes mostly look okay, just wondering if toFileTime should be simplified for the NS case to use FileTime.from(Instant.ofEpochSecond(sec, nsec)). Maybe you've tried this already and are using the Math methods to avoid object allocation?

Yes, it avoids an allocation.

> Can the test using its working directory instead of tmpfs and deleteOnExit. Tests for timestamps on files can take effort to be reliable so it would be useful to not delete the crumbs. 

Here’s a prospective change:

--- a/test/jdk/java/nio/file/attribute/BasicFileAttributeView/SetTimesNanos.java
+++ b/test/jdk/java/nio/file/attribute/BasicFileAttributeView/SetTimesNanos.java
@@ -45,8 +45,8 @@
     public static void main(String[] args) throws IOException,
         InterruptedException {
 
-        Path dir = Files.createTempDirectory("test");
-        dir.toFile().deleteOnExit();
+        Path dirPath = Path.of(System.getProperty("test.dir", "."), "test");
+        Path dir = Files.createDirectory(dirPath);
         FileStore store = Files.getFileStore(dir);
         System.err.format("FileStore: %s on %s (%s)%n", dir, store.name(),
             store.type());

Thanks,

Brian
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190718/8a445968/attachment.html>


More information about the nio-dev mailing list