authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2024-01-15 23:02:50-08:00
committergravatar for noreply@github.comGitHub <noreply@github.com> 2024-01-15 23:02:50-08:00
logd1ce8b8837ef5ede6ccc5fb9118f2c583cfcfa6e
tree1e00c2aff5a4e21a3d671ac02885a7029ad3c854
parentca8c6dd4d65abaadaf0633f4a72e5c0ed79b3c53
parentf25c499d121ab21f1de985da3f36df3cc0118362
signaturebadge-question-mark Signed by PGP key 4AEE18F83AFDEB23

Merge pull request #18168 from cipharius/feature/zig-build-fossil-support

Adds support for Fossil SCM source tree archives as zig build dependencies

2 files changed, 16 insertions(+), 9 deletions(-)

lib/std/tar.zig+13-8
...@@ -536,14 +536,15 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -536,14 +536,15 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
536 while (try iter.next()) |file| {536 while (try iter.next()) |file| {
537 switch (file.kind) {537 switch (file.kind) {
538 .directory => {538 .directory => {
539 const file_name = try stripComponents(file.name, options.strip_components);539 const file_name = stripComponents(file.name, options.strip_components);
540 if (file_name.len != 0 and !options.exclude_empty_directories) {540 if (file_name.len != 0 and !options.exclude_empty_directories) {
541 try dir.makePath(file_name);541 try dir.makePath(file_name);
542 }542 }
543 },543 },
544 .normal => {544 .normal => {
545 if (file.size == 0 and file.name.len == 0) return;545 if (file.size == 0 and file.name.len == 0) return;
546 const file_name = try stripComponents(file.name, options.strip_components);546 const file_name = stripComponents(file.name, options.strip_components);
547 if (file_name.len == 0) return error.BadFileName;
547548
548 const fs_file = dir.createFile(file_name, .{}) catch |err| switch (err) {549 const fs_file = dir.createFile(file_name, .{}) catch |err| switch (err) {
549 error.FileNotFound => again: {550 error.FileNotFound => again: {
...@@ -575,7 +576,8 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -575,7 +576,8 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
575 },576 },
576 .symbolic_link => {577 .symbolic_link => {
577 // The file system path of the symbolic link.578 // The file system path of the symbolic link.
578 const file_name = try stripComponents(file.name, options.strip_components);579 const file_name = stripComponents(file.name, options.strip_components);
580 if (file_name.len == 0) return error.BadFileName;
579 // The data inside the symbolic link.581 // The data inside the symbolic link.
580 const link_name = file.link_name;582 const link_name = file.link_name;
581583
...@@ -604,14 +606,15 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -604,14 +606,15 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
604 }606 }
605}607}
606608
607fn stripComponents(path: []const u8, count: u32) ![]const u8 {609fn stripComponents(path: []const u8, count: u32) []const u8 {
608 var i: usize = 0;610 var i: usize = 0;
609 var c = count;611 var c = count;
610 while (c > 0) : (c -= 1) {612 while (c > 0) : (c -= 1) {
611 if (std.mem.indexOfScalarPos(u8, path, i, '/')) |pos| {613 if (std.mem.indexOfScalarPos(u8, path, i, '/')) |pos| {
612 i = pos + 1;614 i = pos + 1;
613 } else {615 } else {
614 return error.TarComponentsOutsideStrippedPrefix;616 i = path.len;
617 break;
615 }618 }
616 }619 }
617 return path[i..];620 return path[i..];
...@@ -619,9 +622,11 @@ fn stripComponents(path: []const u8, count: u32) ![]const u8 {...@@ -619,9 +622,11 @@ fn stripComponents(path: []const u8, count: u32) ![]const u8 {
619622
620test "tar stripComponents" {623test "tar stripComponents" {
621 const expectEqualStrings = std.testing.expectEqualStrings;624 const expectEqualStrings = std.testing.expectEqualStrings;
622 try expectEqualStrings("a/b/c", try stripComponents("a/b/c", 0));625 try expectEqualStrings("a/b/c", stripComponents("a/b/c", 0));
623 try expectEqualStrings("b/c", try stripComponents("a/b/c", 1));626 try expectEqualStrings("b/c", stripComponents("a/b/c", 1));
624 try expectEqualStrings("c", try stripComponents("a/b/c", 2));627 try expectEqualStrings("c", stripComponents("a/b/c", 2));
628 try expectEqualStrings("", stripComponents("a/b/c", 3));
629 try expectEqualStrings("", stripComponents("a/b/c", 4));
625}630}
626631
627test "tar PaxIterator" {632test "tar PaxIterator" {
src/Package/Fetch.zig+3-1
...@@ -982,7 +982,9 @@ fn unpackResource(...@@ -982,7 +982,9 @@ fn unpackResource(
982 if (ascii.eqlIgnoreCase(mime_type, "application/zstd"))982 if (ascii.eqlIgnoreCase(mime_type, "application/zstd"))
983 break :ft .@"tar.zst";983 break :ft .@"tar.zst";
984984
985 if (!ascii.eqlIgnoreCase(mime_type, "application/octet-stream")) {985 if (!ascii.eqlIgnoreCase(mime_type, "application/octet-stream") and
986 !ascii.eqlIgnoreCase(mime_type, "application/x-compressed"))
987 {
986 return f.fail(f.location_tok, try eb.printString(988 return f.fail(f.location_tok, try eb.printString(
987 "unrecognized 'Content-Type' header: '{s}'",989 "unrecognized 'Content-Type' header: '{s}'",
988 .{content_type},990 .{content_type},