diff options
Diffstat (limited to '')
| -rw-r--r-- | src/fs.zig | 59 |
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(); |