diff options
author | Justin Bedo <cu@cua0.org> | 2022-01-05 13:09:53 +1100 |
---|---|---|
committer | Justin Bedo <cu@cua0.org> | 2022-01-05 13:09:53 +1100 |
commit | 54e45e125435b4a4c133547b7ee9b3c8667ef7dc (patch) | |
tree | 2aea612ec312f20a17106260ccad9b1e74760f4e | |
parent | 0a637afd8bc82d03e474295895251aa47323d747 (diff) |
fix bug in strip-store-paths
also taking the opportunity to simplify the rewriteOutput
function and handle filenames with spaces
-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 |