about summary refs log tree commit diff
path: root/src/fs.zig
diff options
context:
space:
mode:
authorRobert Günzler <r@gnzler.io>2026-01-29 19:16:23 +0100
committerRobert Günzler <r@gnzler.io>2026-01-29 21:05:54 +0100
commit8f8ee8697131ea149568a02b77f23dc8dedae99a (patch)
tree7fad212b20fc623905c74180c292d3a9512a9aa2 /src/fs.zig
parent5ba0af482fe5bef57f99b1f36b7934d672859aaa (diff)
downloadsite-8f8ee8697131ea149568a02b77f23dc8dedae99a.tar.gz
consolidate time access behind getLastEdit
and drop sourcing times from git for now...

Signed-off-by: Robert Günzler <r@gnzler.io>
Diffstat (limited to 'src/fs.zig')
-rw-r--r--src/fs.zig59
1 files changed, 35 insertions, 24 deletions
diff --git a/src/fs.zig b/src/fs.zig
index 64c4b82..d14d7b0 100644
--- a/src/fs.zig
+++ b/src/fs.zig
@@ -142,30 +142,30 @@ pub fn joinPathAndFilename(alloc: std.mem.Allocator, paths: []const []const u8,
     return try std.fs.path.join(alloc, p.items);
 }
 
-pub fn getGitTime(path: []const u8) !std.posix.timespec {
-    var buf = std.mem.zeroes([12]u8);
-
-    var p = std.process.Child.init(
-        &.{ "git", "log", "-1", "--pretty=format:%at", "-z", "--", path },
-        std.heap.page_allocator,
-    );
-    p.stdout_behavior = .Pipe;
-    try p.spawn();
-    _ = try p.stdout.?.readAll(&buf);
-    const result = try p.wait();
-
-    std.debug.assert(result == .Exited and result.Exited == 0);
-
-    // parse result as ulong
-    const gitAuthorDate: c_ulong = c.strtoul(&buf, null, 10);
-    if (gitAuthorDate == 0) return error.NoGitTime;
-
-    // calculate timespec
-    return .{
-        .sec = std.math.cast(isize, gitAuthorDate) orelse std.math.maxInt(isize),
-        .nsec = 0,
-    };
-}
+// pub fn getGitTime(path: []const u8) !std.posix.timespec {
+//     var buf = std.mem.zeroes([12]u8);
+//
+//     var p = std.process.Child.init(
+//         &.{ "git", "log", "-1", "--pretty=format:%at", "-z", "--", path },
+//         std.heap.page_allocator,
+//     );
+//     p.stdout_behavior = .Pipe;
+//     try p.spawn();
+//     _ = try p.stdout.?.readAll(&buf);
+//     const result = try p.wait();
+//
+//     std.debug.assert(result == .Exited and result.Exited == 0);
+//
+//     // parse result as ulong
+//     const gitAuthorDate: c_ulong = c.strtoul(&buf, null, 10);
+//     if (gitAuthorDate == 0) return error.NoGitTime;
+//
+//     // calculate timespec
+//     return .{
+//         .sec = std.math.cast(isize, gitAuthorDate) orelse std.math.maxInt(isize),
+//         .nsec = 0,
+//     };
+// }
 
 pub fn getMtime(path: []const u8) !std.posix.timespec {
     const fd = try std.fs.cwd().openFile(path, .{ .mode = .read_only });
@@ -180,6 +180,17 @@ pub fn getMtime(path: []const u8) !std.posix.timespec {
     };
 }
 
+pub fn getLastEdit(path: []const u8) !std.posix.timespec {
+    std.fs.cwd().access(path, .{}) catch |e| switch (e) {
+        error.FileNotFound => return .{
+            .sec = 0,
+            .nsec = 0,
+        },
+        else => return e,
+    };
+    return getMtime(path);
+}
+
 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();