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
10471047 ));
10481048}
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.
10541050fn unpackResource(
10551051 f: *Fetch,
10561052 resource: *Resource,
......@@ -1751,6 +1747,9 @@ const UnpackResult = struct {
17511747 allocator: std.mem.Allocator,
17521748 errors: std.ArrayListUnmanaged(Error) = .{},
17531749 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.
17541753 root_dir: ?[]const u8 = null,
17551754
17561755 const Error = union(enum) {
......@@ -1774,7 +1773,6 @@ const UnpackResult = struct {
17741773 .unable_to_create_sym_link => |info| info.file_name,
17751774 .unsupported_file_type => |info| info.file_name,
17761775 };
1777
17781776 return !filter.includePath(stripRoot(file_name, root_dir));
17791777 }
17801778
......@@ -1916,8 +1914,8 @@ test "tarball with duplicate file names" {
19161914
19171915 try fb.expectFetchErrors(2,
19181916 \\error: unable to unpack tarball
1919 \\ note: unable to create file 'dir/file': PathAlreadyExists
1920 \\ note: unable to create file 'dir1/file1': PathAlreadyExists
1917 \\ note: unable to create file 'package.tar/dir/file': PathAlreadyExists
1918 \\ note: unable to create file 'package.tar/dir1/file1': PathAlreadyExists
19211919 \\
19221920 );
19231921}
......@@ -2035,7 +2033,6 @@ const TestFetchBuilder = struct {
20352033 defer walker.deinit();
20362034 while (try walker.next()) |entry| {
20372035 if (entry.kind != .file) continue;
2038 // std.debug.print("{s}\n", .{entry.path});
20392036 const path = try std.testing.allocator.dupe(u8, entry.path);
20402037 errdefer std.testing.allocator.free(path);
20412038 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)
20822079 const TarHeader = std.tar.output.Header;
20832080 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
20852092 const files: []const []const u8 = &.{
20862093 "build.zig",
20872094 "src/main.zig",
......@@ -2091,6 +2098,7 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)
20912098 "dir/file",
20922099 "dir1/file1",
20932100 };
2101
20942102 for (files) |path| {
20952103 var hdr = TarHeader.init();
20962104 hdr.typeflag = .regular;
......@@ -2099,6 +2107,7 @@ fn createTestTarball(dir: fs.Dir, tarball_name: []const u8, with_manifest: bool)
20992107 try file.writeAll(std.mem.asBytes(&hdr));
21002108 }
21012109
2110 // add manifest
21022111 if (with_manifest) {
21032112 const build_zig_zon =
21042113 \\ .{