about summary refs log tree commit diff
diff options
context:
space:
mode:
-rw-r--r--src/exe.zig2
-rw-r--r--src/fs.zig59
-rw-r--r--src/gen.zig2
3 files changed, 37 insertions, 26 deletions
diff --git a/src/exe.zig b/src/exe.zig
index c1f084b..6aa260d 100644
--- a/src/exe.zig
+++ b/src/exe.zig
@@ -75,7 +75,7 @@ fn pandocWorker(ctx: *Context, page: []const u8) !void {
     defer ctx.allocator().free(target_path);
 
     // get mtime of the source document
-    const mtime = try (fs.getGitTime(source_path) catch fs.getMtime(source_path));
+    const mtime = try fs.getLastEdit(source_path);
     const mtime_str = try fs.formatTimespec(ctx.allocator(), mtime, "%s");
     defer ctx.allocator().free(mtime_str);
 
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();
diff --git a/src/gen.zig b/src/gen.zig
index 8db8b3f..aec72ca 100644
--- a/src/gen.zig
+++ b/src/gen.zig
@@ -157,7 +157,7 @@ fn genSite(ctx: *Context) !void {
 
 // build a single html file
 fn build(allocator: std.mem.Allocator, w: *std.Io.Writer, page_name: []const u8, srcpath: []const u8) !void {
-    const mtime = try fs.getMtime(srcpath);
+    const mtime = try fs.getLastEdit(srcpath);
     const mtime_str = try fs.formatTimespec(allocator, mtime, "%F");
     defer allocator.free(mtime_str);