RFE: provide an efficient way to retrieve Unix ctime (changed-time)

Marc Strapetz marc.strapetz at syntevo.com
Thu Oct 12 12:38:19 UTC 2017


During a Files.walkFileTree(), UnixFileAttributes seem to be populated 
with all available file system information, especially st_ctime_sec and 
st_ctime_nsec, but currently there is no way to access this information 
(except of using reflection-based hacks).

As suggested in a comment by Alan Bateman on stackoverflow.com[1], this 
information could be made available directly through PosixFileAttributes.

Alternatively I could think of some java.nio.Files utility method:

Filetime getLastChangedTime(BasicFileAttributes) throws IOException;

which will return the ctime in case of UnixFileAttributes and otherwise 
fail with an IOException or even a RuntimeException.

Motivation: combinations of mtime and ctime (and file size), may be used 
on Unix to take a shortcut when it comes to determine file 
modifications. Currently it's not efficiently possible to replicate this 
logic in Java (without the above mentioned hacks). One prominent example 
is Git's Index logic[2].

[1] https://stackoverflow.com/questions/46676279
[2] https://github.com/git/git/blob/master/cache.h

-Marc


More information about the nio-dev mailing list