ADDITIONAL SYSTEM INFORMATION :
Ubuntu Linux 24.04 LTS
openjdk version "23" 2024-09-17
OpenJDK Runtime Environment Corretto-23.0.0.37.1 (build 23+37-FR)
OpenJDK 64-Bit Server VM Corretto-23.0.0.37.1 (build 23+37-FR, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
`BasicFileAttributeView#setTimes` supports nanosecond precision for regular files, but rounds timestamps to microseconds when applied to a symbolic links (or more precisely, when getFileAttributeView() is called with NOFOLLOW_LINKS).
Consider the following example:
```
var target = Path.of("target");
var symlink = Path.of("symlink");
Files.createFile(target);
Files.createSymbolicLink(symlink, target);
var newTime = FileTime.from(1730417633157646106L, NANOSECONDS);
var symlinkView = Files.getFileAttributeView(symlink, BasicFileAttributeView.class, NOFOLLOW_LINKS);
symlinkView.setTimes(newTime, newTime, null);
var symlinkAttrs = symlinkView.readAttributes();
System.out.println("Symlink: " + symlinkAttrs.lastAccessTime().to(NANOSECONDS)
+ " / " + symlinkAttrs.lastModifiedTime().to(NANOSECONDS));
var targetView = Files.getFileAttributeView(symlink, BasicFileAttributeView.class);
targetView.setTimes(newTime, newTime, null);
var targetAttrs = targetView.readAttributes();
System.out.println("Target: " + targetAttrs.lastAccessTime().to(NANOSECONDS) + " / " + targetAttrs.lastModifiedTime().to(NANOSECONDS));
```
Outputs the following to the console:
```
Symlink: 1730417633157646000 / 1730417633157646000
Target: 1730417633157646106 / 1730417633157646106
```
The reason for the lower precision on symbolic links is unclear, at least I can manually set the nanosecond timestamp using `touch`:
```
$ touch -mhd "2024-10-31T23:33:53.157646106Z" symlink
$ TZ=UTC stat -c %y symlink
2024-10-31 23:33:53.157646106 +0000
```
It would be nice if nanosecond precision were supported when using the NOFOLLOW_LINKS attribute as well.
Ubuntu Linux 24.04 LTS
openjdk version "23" 2024-09-17
OpenJDK Runtime Environment Corretto-23.0.0.37.1 (build 23+37-FR)
OpenJDK 64-Bit Server VM Corretto-23.0.0.37.1 (build 23+37-FR, mixed mode, sharing)
A DESCRIPTION OF THE PROBLEM :
`BasicFileAttributeView#setTimes` supports nanosecond precision for regular files, but rounds timestamps to microseconds when applied to a symbolic links (or more precisely, when getFileAttributeView() is called with NOFOLLOW_LINKS).
Consider the following example:
```
var target = Path.of("target");
var symlink = Path.of("symlink");
Files.createFile(target);
Files.createSymbolicLink(symlink, target);
var newTime = FileTime.from(1730417633157646106L, NANOSECONDS);
var symlinkView = Files.getFileAttributeView(symlink, BasicFileAttributeView.class, NOFOLLOW_LINKS);
symlinkView.setTimes(newTime, newTime, null);
var symlinkAttrs = symlinkView.readAttributes();
System.out.println("Symlink: " + symlinkAttrs.lastAccessTime().to(NANOSECONDS)
+ " / " + symlinkAttrs.lastModifiedTime().to(NANOSECONDS));
var targetView = Files.getFileAttributeView(symlink, BasicFileAttributeView.class);
targetView.setTimes(newTime, newTime, null);
var targetAttrs = targetView.readAttributes();
System.out.println("Target: " + targetAttrs.lastAccessTime().to(NANOSECONDS) + " / " + targetAttrs.lastModifiedTime().to(NANOSECONDS));
```
Outputs the following to the console:
```
Symlink: 1730417633157646000 / 1730417633157646000
Target: 1730417633157646106 / 1730417633157646106
```
The reason for the lower precision on symbolic links is unclear, at least I can manually set the nanosecond timestamp using `touch`:
```
$ touch -mhd "2024-10-31T23:33:53.157646106Z" symlink
$ TZ=UTC stat -c %y symlink
2024-10-31 23:33:53.157646106 +0000
```
It would be nice if nanosecond precision were supported when using the NOFOLLOW_LINKS attribute as well.
- relates to
-
JDK-8343785 (fs) Remove syscalls that set file times with microsecond precision
-
- Resolved
-
- links to
-
Commit(master) openjdk/jdk/56c588b4
-
Review(master) openjdk/jdk/21886