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...@@ -1189,9 +1189,9 @@ fn unpackTarball(f: *Fetch, out_dir: fs.Dir, reader: anytype) RunError!UnpackRes
1189 try res.rootErrorMessage("unable to unpack tarball");1189 try res.rootErrorMessage("unable to unpack tarball");
1190 for (diagnostics.errors.items) |item| {1190 for (diagnostics.errors.items) |item| {
1191 switch (item) {1191 switch (item) {
1192 .unable_to_create_file => |i| try res.unableToCreateFile(i.file_name, i.code),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(i.file_name, i.link_name, 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(i.file_name, @intFromEnum(i.file_type)),1194 .unsupported_file_type => |i| try res.unsupportedFileType(stripRoot(i.file_name, res.root_dir), @intFromEnum(i.file_type)),
1195 }1195 }
1196 }1196 }
1197 }1197 }
...@@ -1764,13 +1764,13 @@ const UnpackResult = struct {...@@ -1764,13 +1764,13 @@ const UnpackResult = struct {
1764 file_type: u8,1764 file_type: u8,
1765 },1765 },
17661766
1767 fn excluded(self: Error, filter: Filter, root_dir: []const u8) bool {1767 fn excluded(self: Error, filter: Filter) bool {
1768 const file_name = switch (self) {1768 const file_name = switch (self) {
1769 .unable_to_create_file => |info| info.file_name,1769 .unable_to_create_file => |info| info.file_name,
1770 .unable_to_create_sym_link => |info| info.file_name,1770 .unable_to_create_sym_link => |info| info.file_name,
1771 .unsupported_file_type => |info| info.file_name,1771 .unsupported_file_type => |info| info.file_name,
1772 };1772 };
1773 return !filter.includePath(stripRoot(file_name, root_dir));1773 return !filter.includePath(file_name);
1774 }1774 }
17751775
1776 fn free(self: Error, allocator: std.mem.Allocator) void {1776 fn free(self: Error, allocator: std.mem.Allocator) void {
...@@ -1835,7 +1835,7 @@ const UnpackResult = struct {...@@ -1835,7 +1835,7 @@ const UnpackResult = struct {
1835 while (i > 0) {1835 while (i > 0) {
1836 i -= 1;1836 i -= 1;
1837 const item = self.errors.items[i];1837 const item = self.errors.items[i];
1838 if (item.excluded(filter, self.root_dir)) {1838 if (item.excluded(filter)) {
1839 _ = self.errors.swapRemove(i);1839 _ = self.errors.swapRemove(i);
1840 item.free(self.allocator);1840 item.free(self.allocator);
1841 }1841 }
...@@ -1867,21 +1867,21 @@ const UnpackResult = struct {...@@ -1867,21 +1867,21 @@ const UnpackResult = struct {
1867 .unable_to_create_sym_link => |info| {1867 .unable_to_create_sym_link => |info| {
1868 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{1868 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{
1869 .msg = try eb.printString("unable to create symlink from '{s}' to '{s}': {s}", .{1869 .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),
1871 }),1871 }),
1872 }));1872 }));
1873 },1873 },
1874 .unable_to_create_file => |info| {1874 .unable_to_create_file => |info| {
1875 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{1875 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{
1876 .msg = try eb.printString("unable to create file '{s}': {s}", .{1876 .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),
1878 }),1878 }),
1879 }));1879 }));
1880 },1880 },
1881 .unsupported_file_type => |info| {1881 .unsupported_file_type => |info| {
1882 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{1882 eb.extra.items[note_i] = @intFromEnum(try eb.addErrorMessage(.{
1883 .msg = try eb.printString("file '{s}' has unsupported type '{c}'", .{1883 .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,
1885 }),1885 }),
1886 }));1886 }));
1887 },1887 },