From 54e45e125435b4a4c133547b7ee9b3c8667ef7dc Mon Sep 17 00:00:00 2001 From: Justin Bedo Date: Wed, 5 Jan 2022 13:09:53 +1100 Subject: fix bug in strip-store-paths also taking the opportunity to simplify the rewriteOutput function and handle filenames with spaces --- strip-store-paths/strip-store-paths.zig | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'strip-store-paths') 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 -- cgit v1.2.3