8181493: (fs) Files.readAttributes(path, BasicFileAttributes.class) should preserve nano second time stamps
Lance Andersen
lance.andersen at oracle.com
Thu Jul 18 22:29:54 UTC 2019
HI Brian,
> On Jul 18, 2019, at 11:59 AM, Brian Burkhalter <brian.burkhalter at oracle.com> wrote:
>
>>
>> On Jul 18, 2019, at 7:08 AM, Alan Bateman <Alan.Bateman at oracle.com <mailto: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”);
You should just be able to omit the system property:
http://openjdk.java.net/jtreg/faq.html#scratch-directory
————
3.4 What is a scratch directory?
When jtreg executes a test, the current directory for the test is set to a scratch directory so that the test can easily write any temporary files. jtreg will ensure that the directory is always empty when the test begins, so that the test does not have to worry about deleting any pre-existing files. These directories are placed in the work directory.
-------------
HTH
Best
Lance
> + 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
<http://oracle.com/us/design/oracle-email-sig-198324.gif>
<http://oracle.com/us/design/oracle-email-sig-198324.gif> <http://oracle.com/us/design/oracle-email-sig-198324.gif>
<http://oracle.com/us/design/oracle-email-sig-198324.gif>Lance Andersen| Principal Member of Technical Staff | +1.781.442.2037
Oracle Java Engineering
1 Network Drive
Burlington, MA 01803
Lance.Andersen at oracle.com <mailto:Lance.Andersen at oracle.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190718/243ec011/attachment-0001.html>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: oracle_sig_logo.gif
Type: image/gif
Size: 658 bytes
Desc: not available
URL: <https://mail.openjdk.java.net/pipermail/nio-dev/attachments/20190718/243ec011/oracle_sig_logo-0001.gif>
More information about the nio-dev
mailing list