RFR: 8338884: java/nio/file/attribute/BasicFileAttributeView/CreationTime.java#tmp fails on alinux3 [v2]

SendaoYan syan at openjdk.org
Mon Aug 26 09:57:05 UTC 2024


On Mon, 26 Aug 2024 08:03:31 GMT, Severin Gehwolf <sgehwolf at openjdk.org> wrote:

>> SendaoYan has updated the pull request incrementally with one additional commit since the last revision:
>> 
>>   merge Linker.nativeLinker().defaultLookup().find("statx").isPresent() and !Files.getFileStore(file).type().contentEquals("tmpfs")
>
> test/jdk/java/nio/file/attribute/BasicFileAttributeView/CreationTime.java line 115:
> 
>> 113:             if (statxIsPresent && !Files.getFileStore(file).type().contentEquals("tmpfs")) {
>> 114:                 supportsCreationTimeRead = true;
>> 115:             }
> 
> Noting here that the test could still fail on some other filesystem which might not support birth time. For example `nfs` on Linux (IIRC).

It is difficult to enumerate which file types in Linux do and do not support creation time.
How about add a function that use `stat -c` linux command line to determise support or not.


+    /**
+     * read the output of linux command `stat -c "%w" file`, if the output is "-",
+     * then the file system doesn't support birth time
+     */
+    public static boolean supportBirthTimeOnLinux(Path file) {
+        try {
+            String filePath = file.toAbsolutePath().toString();
+            ProcessBuilder pb = new ProcessBuilder("stat", "-c", "%w", filePath);
+            pb.redirectErrorStream(true);
+            Process p = pb.start();
+            BufferedReader b = new BufferedReader(new InputStreamReader(p.getInputStream()));
+            String l = b.readLine();
+            if (l != null && l.equals("-")) { return false; }
+        } catch(Exception e) {
+        }
+        return true;
+    }

-------------

PR Review Comment: https://git.openjdk.org/jdk/pull/20687#discussion_r1731005570


More information about the nio-dev mailing list