about summary refs log tree commit diff
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2025-10-17 22:51:16 +0200
committerRobert Günzler <r@gnzler.io>2025-10-18 01:30:07 +0200
commit9dd4e7cb2018340886c045adc8d77bc2be17e82f (patch)
treef456c2b0854f91226b7233b866fde397f6b7704e
parent973e5fdb82e0037ba5fc2ff74cf40d32a0e3466b (diff)
downloadsite-9dd4e7cb2018340886c045adc8d77bc2be17e82f.tar.gz
move mtime manipulation into fs function
Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to '')
-rw-r--r--src/exe.zig8
-rw-r--r--src/fs.zig10
2 files changed, 11 insertions, 7 deletions
diff --git a/src/exe.zig b/src/exe.zig
index ae5cfdd..63efd9a 100644
--- a/src/exe.zig
+++ b/src/exe.zig
@@ -77,13 +77,7 @@ fn pandocWorker(ctx: *Context, page: []const u8) !void {
     // fixup mtime of the resulting file, this has to happen after the file
     // swapper has been closed, because it works on a tmp file which is going
     // to be renamed (meaning mtime is changed again)
-    const fd = try std.fs.cwd().openFile(target_path, .{ .mode = .write_only });
-    defer fd.close();
-
-    try std.posix.futimens(
-        fd.handle,
-        &[2]std.os.linux.timespec{ mtime, mtime },
-    );
+    try fs.setMtime(target_path, mtime);
 }
 
 pub fn captureStdout(ctx: *Context, argv: []const []const u8, env_map: ?*std.process.EnvMap, buf: std.io.AnyWriter) !void {
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);