Skip to content

Commit d1ce8b8

Browse files
authored
Merge pull request #18168 from cipharius/feature/zig-build-fossil-support
Adds support for Fossil SCM source tree archives as zig build dependencies
2 parents ca8c6dd + f25c499 commit d1ce8b8

File tree

2 files changed

+16
-9
lines changed

2 files changed

+16
-9
lines changed

lib/std/tar.zig

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -536,14 +536,15 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
536536
while (try iter.next()) |file| {
537537
switch (file.kind) {
538538
.directory => {
539-
const file_name = try stripComponents(file.name, options.strip_components);
539+
const file_name = stripComponents(file.name, options.strip_components);
540540
if (file_name.len != 0 and !options.exclude_empty_directories) {
541541
try dir.makePath(file_name);
542542
}
543543
},
544544
.normal => {
545545
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

548549
const fs_file = dir.createFile(file_name, .{}) catch |err| switch (err) {
549550
error.FileNotFound => again: {
@@ -575,7 +576,8 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
575576
},
576577
.symbolic_link => {
577578
// 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;
579581
// The data inside the symbolic link.
580582
const link_name = file.link_name;
581583

@@ -604,24 +606,27 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
604606
}
605607
}
606608

607-
fn stripComponents(path: []const u8, count: u32) ![]const u8 {
609+
fn stripComponents(path: []const u8, count: u32) []const u8 {
608610
var i: usize = 0;
609611
var c = count;
610612
while (c > 0) : (c -= 1) {
611613
if (std.mem.indexOfScalarPos(u8, path, i, '/')) |pos| {
612614
i = pos + 1;
613615
} else {
614-
return error.TarComponentsOutsideStrippedPrefix;
616+
i = path.len;
617+
break;
615618
}
616619
}
617620
return path[i..];
618621
}
619622

620623
test "tar stripComponents" {
621624
const expectEqualStrings = std.testing.expectEqualStrings;
622-
try expectEqualStrings("a/b/c", try stripComponents("a/b/c", 0));
623-
try expectEqualStrings("b/c", try stripComponents("a/b/c", 1));
624-
try expectEqualStrings("c", try stripComponents("a/b/c", 2));
625+
try expectEqualStrings("a/b/c", stripComponents("a/b/c", 0));
626+
try expectEqualStrings("b/c", stripComponents("a/b/c", 1));
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));
625630
}
626631

627632
test "tar PaxIterator" {

src/Package/Fetch.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -982,7 +982,9 @@ fn unpackResource(
982982
if (ascii.eqlIgnoreCase(mime_type, "application/zstd"))
983983
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+
{
986988
return f.fail(f.location_tok, try eb.printString(
987989
"unrecognized 'Content-Type' header: '{s}'",
988990
.{content_type},

0 commit comments

Comments
 (0)