RFR: 8338884: java/nio/file/attribute/BasicFileAttributeView/CreationTime.java#tmp fails on alinux3 [v2]
Severin Gehwolf
sgehwolf at openjdk.org
Mon Aug 26 10:08:05 UTC 2024
On Mon, 26 Aug 2024 09:53:57 GMT, SendaoYan <syan at openjdk.org> wrote:
>> 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;
> + }
It's a possibility. I'm fine with the current "tmpfs" special case in the test, but I guess what you proposed above would be more robust. So if others are OK with such an approach, that would be fine with me as well.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20687#discussion_r1731020143
More information about the nio-dev
mailing list