| ... | ... | @@ -7,27 +7,27 @@ pub const Directory = struct { |
| 7 | 7 | /// directly, but it is needed when passing the directory to a child process. |
| 8 | 8 | /// `null` means cwd. |
| 9 | 9 | path: ?[]const u8, |
| 10 | | handle: std.fs.Dir, |
| 10 | handle: fs.Dir, |
| 11 | 11 | |
| 12 | 12 | pub fn join(self: Directory, allocator: Allocator, paths: []const []const u8) ![]u8 { |
| 13 | 13 | if (self.path) |p| { |
| 14 | 14 | // TODO clean way to do this with only 1 allocation |
| 15 | | const part2 = try std.fs.path.join(allocator, paths); |
| 15 | const part2 = try fs.path.join(allocator, paths); |
| 16 | 16 | defer allocator.free(part2); |
| 17 | | return std.fs.path.join(allocator, &[_][]const u8{ p, part2 }); |
| 17 | return fs.path.join(allocator, &[_][]const u8{ p, part2 }); |
| 18 | 18 | } else { |
| 19 | | return std.fs.path.join(allocator, paths); |
| 19 | return fs.path.join(allocator, paths); |
| 20 | 20 | } |
| 21 | 21 | } |
| 22 | 22 | |
| 23 | 23 | pub fn joinZ(self: Directory, allocator: Allocator, paths: []const []const u8) ![:0]u8 { |
| 24 | 24 | if (self.path) |p| { |
| 25 | 25 | // TODO clean way to do this with only 1 allocation |
| 26 | | const part2 = try std.fs.path.join(allocator, paths); |
| 26 | const part2 = try fs.path.join(allocator, paths); |
| 27 | 27 | defer allocator.free(part2); |
| 28 | | return std.fs.path.joinZ(allocator, &[_][]const u8{ p, part2 }); |
| 28 | return fs.path.joinZ(allocator, &[_][]const u8{ p, part2 }); |
| 29 | 29 | } else { |
| 30 | | return std.fs.path.joinZ(allocator, paths); |
| 30 | return fs.path.joinZ(allocator, paths); |
| 31 | 31 | } |
| 32 | 32 | } |
| 33 | 33 | |
| ... | ... | @@ -39,6 +39,20 @@ pub const Directory = struct { |
| 39 | 39 | if (self.path) |p| gpa.free(p); |
| 40 | 40 | self.* = undefined; |
| 41 | 41 | } |
| 42 | |
| 43 | pub fn format( |
| 44 | self: Directory, |
| 45 | comptime fmt_string: []const u8, |
| 46 | options: fmt.FormatOptions, |
| 47 | writer: anytype, |
| 48 | ) !void { |
| 49 | _ = options; |
| 50 | if (fmt_string.len != 0) fmt.invalidFmtError(fmt, self); |
| 51 | if (self.path) |p| { |
| 52 | try writer.writeAll(p); |
| 53 | try writer.writeAll(fs.path.sep_str); |
| 54 | } |
| 55 | } |
| 42 | 56 | }; |
| 43 | 57 | |
| 44 | 58 | gpa: Allocator, |
| ... | ... | @@ -243,10 +257,10 @@ pub const HashHelper = struct { |
| 243 | 257 | hh.hasher.final(&bin_digest); |
| 244 | 258 | |
| 245 | 259 | var out_digest: [hex_digest_len]u8 = undefined; |
| 246 | | _ = std.fmt.bufPrint( |
| 260 | _ = fmt.bufPrint( |
| 247 | 261 | &out_digest, |
| 248 | 262 | "{s}", |
| 249 | | .{std.fmt.fmtSliceHexLower(&bin_digest)}, |
| 263 | .{fmt.fmtSliceHexLower(&bin_digest)}, |
| 250 | 264 | ) catch unreachable; |
| 251 | 265 | return out_digest; |
| 252 | 266 | } |
| ... | ... | @@ -365,10 +379,10 @@ pub const Manifest = struct { |
| 365 | 379 | var bin_digest: BinDigest = undefined; |
| 366 | 380 | self.hash.hasher.final(&bin_digest); |
| 367 | 381 | |
| 368 | | _ = std.fmt.bufPrint( |
| 382 | _ = fmt.bufPrint( |
| 369 | 383 | &self.hex_digest, |
| 370 | 384 | "{s}", |
| 371 | | .{std.fmt.fmtSliceHexLower(&bin_digest)}, |
| 385 | .{fmt.fmtSliceHexLower(&bin_digest)}, |
| 372 | 386 | ) catch unreachable; |
| 373 | 387 | |
| 374 | 388 | self.hash.hasher = hasher_init; |
| ... | ... | @@ -469,7 +483,7 @@ pub const Manifest = struct { |
| 469 | 483 | cache_hash_file.stat.size = fmt.parseInt(u64, size, 10) catch return error.InvalidFormat; |
| 470 | 484 | cache_hash_file.stat.inode = fmt.parseInt(fs.File.INode, inode, 10) catch return error.InvalidFormat; |
| 471 | 485 | cache_hash_file.stat.mtime = fmt.parseInt(i64, mtime_nsec_str, 10) catch return error.InvalidFormat; |
| 472 | | _ = std.fmt.hexToBytes(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat; |
| 486 | _ = fmt.hexToBytes(&cache_hash_file.bin_digest, digest_str) catch return error.InvalidFormat; |
| 473 | 487 | const prefix = fmt.parseInt(u8, prefix_str, 10) catch return error.InvalidFormat; |
| 474 | 488 | if (prefix >= self.cache.prefixes_len) return error.InvalidFormat; |
| 475 | 489 | |
| ... | ... | @@ -806,10 +820,10 @@ pub const Manifest = struct { |
| 806 | 820 | self.hash.hasher.final(&bin_digest); |
| 807 | 821 | |
| 808 | 822 | var out_digest: [hex_digest_len]u8 = undefined; |
| 809 | | _ = std.fmt.bufPrint( |
| 823 | _ = fmt.bufPrint( |
| 810 | 824 | &out_digest, |
| 811 | 825 | "{s}", |
| 812 | | .{std.fmt.fmtSliceHexLower(&bin_digest)}, |
| 826 | .{fmt.fmtSliceHexLower(&bin_digest)}, |
| 813 | 827 | ) catch unreachable; |
| 814 | 828 | |
| 815 | 829 | return out_digest; |
| ... | ... | @@ -831,10 +845,10 @@ pub const Manifest = struct { |
| 831 | 845 | var encoded_digest: [hex_digest_len]u8 = undefined; |
| 832 | 846 | |
| 833 | 847 | for (self.files.items) |file| { |
| 834 | | _ = std.fmt.bufPrint( |
| 848 | _ = fmt.bufPrint( |
| 835 | 849 | &encoded_digest, |
| 836 | 850 | "{s}", |
| 837 | | .{std.fmt.fmtSliceHexLower(&file.bin_digest)}, |
| 851 | .{fmt.fmtSliceHexLower(&file.bin_digest)}, |
| 838 | 852 | ) catch unreachable; |
| 839 | 853 | try writer.print("{d} {d} {d} {s} {d} {s}\n", .{ |
| 840 | 854 | file.stat.size, |