RFR: 8338884: java/nio/file/attribute/BasicFileAttributeView/CreationTime.java#tmp fails on alinux3 [v2]
SendaoYan
syan at openjdk.org
Mon Aug 26 12:17:36 UTC 2024
On Mon, 26 Aug 2024 10:05:41 GMT, Severin Gehwolf <sgehwolf at openjdk.org> wrote:
>> 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.
Use `stat -c` linux command line to determise support `create time` or not.
-------------
PR Review Comment: https://git.openjdk.org/jdk/pull/20687#discussion_r1731153397
More information about the nio-dev
mailing list