aboutsummaryrefslogtreecommitdiff
path: root/strip-store-paths
diff options
context:
space:
mode:
authorJustin Bedo <cu@cua0.org>2022-01-05 13:09:53 +1100
committerJustin Bedo <cu@cua0.org>2022-01-05 13:09:53 +1100
commit54e45e125435b4a4c133547b7ee9b3c8667ef7dc (patch)
tree2aea612ec312f20a17106260ccad9b1e74760f4e /strip-store-paths
parent0a637afd8bc82d03e474295895251aa47323d747 (diff)
fix bug in strip-store-paths
also taking the opportunity to simplify the rewriteOutput function and handle filenames with spaces
Diffstat (limited to 'strip-store-paths')
-rw-r--r--strip-store-paths/strip-store-paths.zig9
1 files changed, 8 insertions, 1 deletions
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