authorgravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-04-04 17:56:14+02:00
committergravatar for igor.anic@gmail.comIgor Anić <igor.anic@gmail.com> 2024-04-09 15:00:21+02:00
log22e9c50376b8d7f2c67e3727bc40c697942576c8
tree3416bcb3aa2a7581d62c13ef23c64917ca13182c
parentfc745fb05c2ab34c5589d3f04700d0e4d537ed68

fetch: fix test tarball

Should include folder structure, at least root folder so it can be found in pipeToFileSystem.

1 files changed, 17 insertions(+), 8 deletions(-)

src/Package/Fetch.zig+17-8
...@@ -1047,10 +1047,6 @@ fn initResource(f: *Fetch, uri: std.Uri, server_header_buffer: []u8) RunError!Re...@@ -1047,10 +1047,6 @@ fn initResource(f: *Fetch, uri: std.Uri, server_header_buffer: []u8) RunError!Re
1047 ));1047 ));
1048}1048}
10491049
1050/// A `null` return value indicates the `tmp_directory` is populated directly
1051/// with the package contents.
1052/// A non-null return value means that the package contents are inside a
1053/// sub-directory indicated by the named path.
1054fn unpackResource(1050fn unpackResource(
1055 f: *Fetch,1051 f: *Fetch,
1056 resource: *Resource,1052 resource: *Resource,
...@@ -1751,6 +1747,9 @@ const UnpackResult = struct {...@@ -1751,6 +1747,9 @@ const UnpackResult = struct {
1751 allocator: std.mem.Allocator,1747 allocator: std.mem.Allocator,
1752 errors: std.ArrayListUnmanaged(Error) = .{},1748 errors: std.ArrayListUnmanaged(Error) = .{},
1753 root_error_message: []const u8 = "",1749 root_error_message: []const u8 = "",
1750
1751 // A `null` value indicates the `tmp_directory` is populated directly with the package contents.
1752 // A non-null value means that the package contents are inside a sub-directory indicated by the named path.
1754 root_dir: ?[]const u8 = null,1753 root_dir: ?[]const u8 = null,
17551754
1756 const Error = union(enum) {1755 const Error = union(enum) {
...@@ -1774,7 +1773,6 @@ const UnpackResult = struct {...@@ -1774,7 +1773,6 @@ const UnpackResult = struct {
1774 .unable_to_create_sym_link => |info| info.file_name,1773 .unable_to_create_sym_link => |info| info.file_name,
1775 .unsupported_file_type => |info| info.file_name,1774 .unsupported_file_type => |info| info.file_name,
1776 };1775 };
1777
1778 return !filter.includePath(stripRoot(file_name, root_dir));1776 return !filter.includePath(stripRoot(file_name, root_dir));
1779 }1777 }
17801778
...@@ -1916,8 +1914,8 @@ test "tarball with duplicate file names" {...@@ -1916,8 +1914,8 @@ test "tarball with duplicate file names" {
19161914
1917 try fb.expectFetchErrors(2,1915 try fb.expectFetchErrors(2,
1918 \\error: unable to unpack tarball1916 \\error: unable to unpack tarball
1919 \\ note: unable to create file 'dir/file': PathAlreadyExists1917 \\ note: unable to create file 'package.tar/dir/file': PathAlreadyExists
1920 \\ note: unable to create file 'dir1/file1': PathAlreadyExists1918 \\ note: unable to create file 'package.tar/dir1/file1': PathAlreadyExists
1921 \\1919 \\
1922 );1920 );
1923}1921}
...@@ -2035,7 +2033,6 @@ const TestFetchBuilder = struct {...@@ -2035,7 +2033,6 @@ const TestFetchBuilder = struct {
2035 defer walker.deinit();2033 defer walker.deinit();
2036 while (try walker.next()) |entry| {2034 while (try walker.next()) |entry| {
2037 if (entry.kind != .file) continue;2035 if (entry.kind != .file) continue;
2038 // std.debug.print("{s}\n", .{entry.path});
2039 const path = try std.testing.allocator.dupe(u8, entry.path);2036 const path = try std.testing.allocator.dupe(u8, entry.path);
2040 errdefer std.testing.allocator.free(path);2037 errdefer std.testing.allocator.free(path);
2041 std.mem.replaceScalar(u8, path, std.fs.path.sep, '/');2038 std.mem.replaceScalar(u8, path, std.fs.path.sep, '/');
...@@ -2082,6 +2079,16 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)...@@ -2082,6 +2079,16 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)
2082 const TarHeader = std.tar.output.Header;2079 const TarHeader = std.tar.output.Header;
2083 const prefix = tarball_name;2080 const prefix = tarball_name;
20842081
2082 // add root directory
2083 {
2084 var hdr = TarHeader.init();
2085 hdr.typeflag = .directory;
2086 try hdr.setPath(prefix, "");
2087 try hdr.updateChecksum();
2088 try file.writeAll(std.mem.asBytes(&hdr));
2089 }
2090
2091 // add files
2085 const files: []const []const u8 = &.{2092 const files: []const []const u8 = &.{
2086 "build.zig",2093 "build.zig",
2087 "src/main.zig",2094 "src/main.zig",
...@@ -2091,6 +2098,7 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)...@@ -2091,6 +2098,7 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)
2091 "dir/file",2098 "dir/file",
2092 "dir1/file1",2099 "dir1/file1",
2093 };2100 };
2101
2094 for (files) |path| {2102 for (files) |path| {
2095 var hdr = TarHeader.init();2103 var hdr = TarHeader.init();
2096 hdr.typeflag = .regular;2104 hdr.typeflag = .regular;
...@@ -2099,6 +2107,7 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)...@@ -2099,6 +2107,7 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)
2099 try file.writeAll(std.mem.asBytes(&hdr));2107 try file.writeAll(std.mem.asBytes(&hdr));
2100 }2108 }
21012109
2110 // add manifest
2102 if (with_manifest) {2111 if (with_manifest) {
2103 const build_zig_zon =2112 const build_zig_zon =
2104 \\ .{2113 \\ .{