diff options
-rw-r--r-- | default.nix | 8 | ||||
-rw-r--r-- | strip-store-paths/strip-store-paths.zig | 9 |
2 files changed, 9 insertions, 8 deletions
diff --git a/default.nix b/default.nix index 04fd62c..3ec0450 100644 --- a/default.nix +++ b/default.nix @@ -151,13 +151,7 @@ let stripCommand = '' function rewriteOutput { - if [ -f ''${!1} ] ; then - strip-store-paths ''${!1} - else - for f in $(find ''${!1} -type f) ; do - strip-store-paths $f - done - fi + find ''${!1} -type f -print0 | xargs -0 -n1 strip-store-paths } for o in $outputs ; do rewriteOutput $o diff --git a/strip-store-paths/strip-store-paths.zig b/strip-store-paths/strip-store-paths.zig index 243bd4a..9ded95e 100644 --- a/strip-store-paths/strip-store-paths.zig +++ b/strip-store-paths/strip-store-paths.zig @@ -7,6 +7,9 @@ pub const File = struct { pub fn init(fd: std.os.fd_t, allocator: std.mem.Allocator) !File { var stats = try std.os.fstat(fd); + if (stats.size == 0) { + return error.ZeroFile; + } var ptr = try std.os.mmap(null, @intCast(usize, stats.size), std.os.PROT.READ | std.os.PROT.WRITE, std.os.MAP.SHARED, fd, 0); return File{ .ptr = ptr, .len = @intCast(u64, stats.size), .allocator = allocator }; } @@ -32,7 +35,11 @@ pub fn main() !void { // mmap input var fd = try std.os.open(path, std.os.O.RDWR, 0); - var input = try File.init(fd, allocator); + var input = File.init(fd, allocator) catch |err| if (err == error.ZeroFile) { + return; + } else { + return err; + }; defer input.deinit(); // search for /nix/store |