From 9dd4e7cb2018340886c045adc8d77bc2be17e82f Mon Sep 17 00:00:00 2001 From: Robert Günzler Date: Fri, 17 Oct 2025 22:51:16 +0200 Subject: move mtime manipulation into fs function MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Robert Günzler --- src/fs.zig | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 'src/fs.zig') diff --git a/src/fs.zig b/src/fs.zig index 045db89..adcd0c3 100644 --- a/src/fs.zig +++ b/src/fs.zig @@ -179,6 +179,16 @@ pub fn getMtime(path: []const u8) !std.posix.timespec { }; } +pub fn setMtime(path: []const u8, ts: std.posix.timespec) !void { + const fd = try std.fs.cwd().openFile(path, .{ .mode = .write_only }); + defer fd.close(); + + try std.posix.futimens( + fd.handle, + &[2]std.os.linux.timespec{ ts, ts }, + ); +} + // use libc strftime to format time string pub fn formatTimespec(alloc: std.mem.Allocator, timespec: std.posix.timespec, fmt: [*c]const u8) ![]const u8 { const mtime_str = try alloc.alloc(u8, std.os.linux.PATH_MAX); -- cgit 1.4.1