I recently learned that different OSes and even different filesystems under the same OS support different subsets of the timestamps returned by lstat
.
The Stats
object returned gives us four times, each in two different flavours.
js Date objects:
atime
: the last time this file was accessed expressed in milliseconds since the POSIX Epochmtime
: the last time this file was modified ...ctime
: the last time the file status was changed ...birthtime
: the creation time of this file
(atimeMs
, mtimeMs
, ctimeMs
, and birthtimeMs
are js Date object versions of each of the above)
"Modified" means the file's contents were changed by being written to etc. "Changed" means the file's metadata such as owners and permissions was changed.
Linux has traditionally never supported the concept of birth time, but as more newer filesystems did support it, it has recently had support added to hopefully all relevant layers of the Linux stack if I have read correctly.
But Windows and Mac both do support birth time as do their native filesystems.
Windows on the other hand did not traditionally support a concept of file change separate from file modification. But to comply to POSIX it added support at the API level and to NTFS. (It doesn't seem to be exposed anywhere in the GUI or commandline though). FAT fs does not support it.
When I call lstat
on a file on Windows on an NTFS drive the results for ctime
look good. When I call it on a file on a FAT drive, ctime
contains junk. (In my case it's always 2076-11-29T08:54:34.955Z
for every file.)
I don't know if this is a bug.
I don't know what birthtime
returns on Linux on filesystems that don't support it. Hopefully null
or undefined
but perhaps also garbage. I also don't know what Linux or Mac return in ctime
for files on FAT volumes.
So is there a way in Node to get info on which of these features are supported for a given file/path/fs?
birthtime
can be relied upon in Linux? i posted a question here – Kienan