authorgravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-04-04 21:39:13+02:00
committergravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-04-09 15:00:22+02:00
log8c58b8fe0107fe3e06ec8bac2b2c25f706406c82
tree0b935e778f0141f5c40f2156f1b093cd3ceb6932
parentb422e4a202f3b4d6e33c1433c3d27152dc5bc925

fetch: refactor package root in errors

Use stripRoot in less places. Strip it while copying error from diagnostic to unpack result so other palaces can be free of this logic.

1 files changed, 9 insertions(+), 9 deletions(-)

src/Package/Fetch.zig+9-9
......@@ -1189,9 +1189,9 @@ fn unpackTarball(f: *Fetch, out_dir: fs.Dir, reader: anytype) RunError!UnpackRes
11891189 try res.rootErrorMessage("unable to unpack tarball");
11901190 for (diagnostics.errors.items) |item| {
11911191 switch (item) {
1192 .unable_to_create_file => |i| try res.unableToCreateFile(i.file_name, i.code),
1193 .unable_to_create_sym_link => |i| try res.unableToCreateSymLink(i.file_name, i.link_name, i.code),
1194 .unsupported_file_type => |i| try res.unsupportedFileType(i.file_name, @intFromEnum(i.file_type)),
1192 .unable_to_create_file => |i| try res.unableToCreateFile(stripRoot(i.file_name, res.root_dir), i.code),
1193 .unable_to_create_sym_link => |i| try res.unableToCreateSymLink(stripRoot(i.file_name, res.root_dir), i.link_name, i.code),
1194 .unsupported_file_type => |i| try res.unsupportedFileType(stripRoot(i.file_name, res.root_dir), @intFromEnum(i.file_type)),
11951195 }
11961196 }
11971197 }
......@@ -1764,13 +1764,13 @@ const UnpackResult = struct {
17641764 file_type: u8,
17651765 },
17661766
1767 fn excluded(self: Error, filter: Filter, root_dir: []const u8) bool {
1767 fn excluded(self: Error, filter: Filter) bool {
17681768 const file_name = switch (self) {
17691769 .unable_to_create_file => |info| info.file_name,
17701770 .unable_to_create_sym_link => |info| info.file_name,
17711771 .unsupported_file_type => |info| info.file_name,
17721772 };
1773 return !filter.includePath(stripRoot(file_name, root_dir));
1773 return !filter.includePath(file_name);
17741774 }
17751775
17761776 fn free(self: Error, allocator: std.mem.Allocator) void {
......@@ -1835,7 +1835,7 @@ const UnpackResult = struct {
18351835 while (i > 0) {
18361836 i -= 1;
18371837 const item = self.errors.items[i];
1838 if (item.excluded(filter, self.root_dir)) {
1838 if (item.excluded(filter)) {
18391839 _ = self.errors.swapRemove(i);
18401840 item.free(self.allocator);
18411841 }
......@@ -1867,21 +1867,21 @@ const UnpackResult = struct {
18671867 .unable_to_create_sym_link => |info| {
18681868 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{
18691869 .msg = try eb.printString("unable to create symlink from '{s}' to '{s}': {s}", .{
1870 stripRoot(info.file_name, self.root_dir), info.link_name, @errorName(info.code),
1870 info.file_name, info.link_name, @errorName(info.code),
18711871 }),
18721872 }));
18731873 },
18741874 .unable_to_create_file => |info| {
18751875 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{
18761876 .msg = try eb.printString("unable to create file '{s}': {s}", .{
1877 stripRoot(info.file_name, self.root_dir), @errorName(info.code),
1877 info.file_name, @errorName(info.code),
18781878 }),
18791879 }));
18801880 },
18811881 .unsupported_file_type => |info| {
18821882 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{
18831883 .msg = try eb.printString("file '{s}' has unsupported type '{c}'", .{
1884 stripRoot(info.file_name, self.root_dir), info.file_type,
1884 info.file_name, info.file_type,
18851885 }),
18861886 }));
18871887 },