Fix Stat.ctime docs, and correct its value on Windows

ctime is last file status/metadata change, not creation time. Note that this mistake was not made in the `File.metadata`/`File.Metadata` implementation, which allows getting the actual creation time.

Closes #18290
This commit is contained in:
Ryan Liptak 2023-12-19 21:07:22 -08:00 committed by Veikka Tuominen
parent 697b8f7d2f
commit dd189a354b

View File

@ -315,11 +315,11 @@ pub const Stat = struct {
mode: Mode,
kind: Kind,
/// Access time in nanoseconds, relative to UTC 1970-01-01.
/// Last access time in nanoseconds, relative to UTC 1970-01-01.
atime: i128,
/// Last modification time in nanoseconds, relative to UTC 1970-01-01.
mtime: i128,
/// Creation time in nanoseconds, relative to UTC 1970-01-01.
/// Last status/metadata change time in nanoseconds, relative to UTC 1970-01-01.
ctime: i128,
pub fn fromSystem(st: posix.system.Stat) Stat {
@ -369,6 +369,8 @@ pub const Stat = struct {
pub const StatError = posix.FStatError;
/// Returns `Stat` containing basic information about the `File`.
/// Use `metadata` to retrieve more detailed information (e.g. creation time, permissions).
/// TODO: integrate with async I/O
pub fn stat(self: File) StatError!Stat {
if (builtin.os.tag == .windows) {
@ -392,7 +394,7 @@ pub fn stat(self: File) StatError!Stat {
.kind = if (info.StandardInformation.Directory == 0) .file else .directory,
.atime = windows.fromSysTime(info.BasicInformation.LastAccessTime),
.mtime = windows.fromSysTime(info.BasicInformation.LastWriteTime),
.ctime = windows.fromSysTime(info.BasicInformation.CreationTime),
.ctime = windows.fromSysTime(info.BasicInformation.ChangeTime),
};
}