From dd189a354bf1c77b1996725902c7f29526cc22a4 Mon Sep 17 00:00:00 2001 From: Ryan Liptak Date: Tue, 19 Dec 2023 21:07:22 -0800 Subject: [PATCH] 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 --- lib/std/fs/File.zig | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/lib/std/fs/File.zig b/lib/std/fs/File.zig index 464e7207dc..0d16db2d85 100644 --- a/lib/std/fs/File.zig +++ b/lib/std/fs/File.zig @@ -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), }; }