authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-26 20:53:29-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2026-03-27 01:27:26-07:00
log79b5433da713a1d60b8651c34a2459833900f4fa
tree0e18662819695b17dafc2b56c6f0e0dea9155c05
parent0d25302d43557d89b868b8925b2e98395d1ebe60

std.tar: rename pipeToFileSystem to extract


1 files changed, 22 insertions(+), 16 deletions(-)

lib/std/tar.zig+22-16
......@@ -120,8 +120,10 @@ pub const Diagnostics = struct {
120120 }
121121};
122122
123/// pipeToFileSystem options
124pub const PipeOptions = struct {
123/// Deprecated, renamed to `ExtractOptions`.
124pub const PipeOptions = ExtractOptions;
125
126pub const ExtractOptions = struct {
125127 /// Number of directory levels to skip when extracting files.
126128 strip_components: u32 = 0,
127129 /// How to handle the "mode" property of files from within the tar file.
......@@ -580,8 +582,12 @@ pub const PaxIterator = struct {
580582 }
581583};
582584
583/// Saves tar file content to the file systems.
584pub fn pipeToFileSystem(io: Io, dir: Io.Dir, reader: *Io.Reader, options: PipeOptions) !void {
585/// Deprecated, renamed to `extract`.
586pub const pipeToFileSystem = extract;
587
588/// Ingests tar file from `reader`, populating file contents within `dir`. If
589/// any file would be extracted outside of `dir`, an error is return instead.
590pub fn extract(io: Io, dir: Io.Dir, reader: *Io.Reader, options: ExtractOptions) !void {
585591 var file_name_buffer: [std.fs.max_path_bytes]u8 = undefined;
586592 var link_name_buffer: [std.fs.max_path_bytes]u8 = undefined;
587593 var file_contents_buffer: [1024]u8 = undefined;
......@@ -958,7 +964,7 @@ test Iterator {
958964 }
959965}
960966
961test pipeToFileSystem {
967test extract {
962968 const io = testing.io;
963969 // Example tar file is created from this tree structure:
964970 // $ tree example
......@@ -987,7 +993,7 @@ test pipeToFileSystem {
987993 const dir = tmp.dir;
988994
989995 // Save tar from reader to the file system `dir`
990 pipeToFileSystem(io, dir, &reader, .{
996 extract(io, dir, &reader, .{
991997 .mode_mode = .ignore,
992998 .strip_components = 1,
993999 .exclude_empty_directories = true,
......@@ -1009,7 +1015,7 @@ test pipeToFileSystem {
10091015 );
10101016}
10111017
1012test "pipeToFileSystem root_dir" {
1018test "extract root_dir" {
10131019 const io = testing.io;
10141020 const data = @embedFile("tar/testdata/example.tar");
10151021 var reader: Io.Reader = .fixed(data);
......@@ -1021,7 +1027,7 @@ test "pipeToFileSystem root_dir" {
10211027 var diagnostics: Diagnostics = .{ .allocator = testing.allocator };
10221028 defer diagnostics.deinit();
10231029
1024 pipeToFileSystem(io, tmp.dir, &reader, .{
1030 extract(io, tmp.dir, &reader, .{
10251031 .strip_components = 1,
10261032 .diagnostics = &diagnostics,
10271033 }) catch |err| {
......@@ -1043,7 +1049,7 @@ test "pipeToFileSystem root_dir" {
10431049 var diagnostics: Diagnostics = .{ .allocator = testing.allocator };
10441050 defer diagnostics.deinit();
10451051
1046 pipeToFileSystem(io, tmp.dir, &reader, .{
1052 extract(io, tmp.dir, &reader, .{
10471053 .strip_components = 0,
10481054 .diagnostics = &diagnostics,
10491055 }) catch |err| {
......@@ -1068,7 +1074,7 @@ test "findRoot with single file archive" {
10681074
10691075 var diagnostics: Diagnostics = .{ .allocator = testing.allocator };
10701076 defer diagnostics.deinit();
1071 try pipeToFileSystem(io, tmp.dir, &reader, .{ .diagnostics = &diagnostics });
1077 try extract(io, tmp.dir, &reader, .{ .diagnostics = &diagnostics });
10721078
10731079 try testing.expectEqualStrings("", diagnostics.root_dir);
10741080}
......@@ -1083,12 +1089,12 @@ test "findRoot without explicit root dir" {
10831089
10841090 var diagnostics: Diagnostics = .{ .allocator = testing.allocator };
10851091 defer diagnostics.deinit();
1086 try pipeToFileSystem(io, tmp.dir, &reader, .{ .diagnostics = &diagnostics });
1092 try extract(io, tmp.dir, &reader, .{ .diagnostics = &diagnostics });
10871093
10881094 try testing.expectEqualStrings("root", diagnostics.root_dir);
10891095}
10901096
1091test "pipeToFileSystem strip_components" {
1097test "extract strip_components" {
10921098 const io = testing.io;
10931099 const data = @embedFile("tar/testdata/example.tar");
10941100 var reader: Io.Reader = .fixed(data);
......@@ -1098,7 +1104,7 @@ test "pipeToFileSystem strip_components" {
10981104 var diagnostics: Diagnostics = .{ .allocator = testing.allocator };
10991105 defer diagnostics.deinit();
11001106
1101 pipeToFileSystem(io, tmp.dir, &reader, .{
1107 extract(io, tmp.dir, &reader, .{
11021108 .strip_components = 3,
11031109 .diagnostics = &diagnostics,
11041110 }) catch |err| {
......@@ -1120,7 +1126,7 @@ fn normalizePath(bytes: []u8) []u8 {
11201126}
11211127
11221128// File system mode based on tar header mode and mode_mode options.
1123fn filePermissions(mode: u32, options: PipeOptions) Io.File.Permissions {
1129fn filePermissions(mode: u32, options: ExtractOptions) Io.File.Permissions {
11241130 return if (!Io.File.Permissions.has_executable_bit or options.mode_mode == .ignore or (mode & 0o100) == 0)
11251131 .default_file
11261132 else
......@@ -1142,13 +1148,13 @@ test "executable bit" {
11421148 const S = std.posix.S;
11431149 const data = @embedFile("tar/testdata/example.tar");
11441150
1145 for ([_]PipeOptions.ModeMode{ .ignore, .executable_bit_only }) |opt| {
1151 for ([_]ExtractOptions.ModeMode{ .ignore, .executable_bit_only }) |opt| {
11461152 var reader: Io.Reader = .fixed(data);
11471153
11481154 var tmp = testing.tmpDir(.{ .follow_symlinks = false });
11491155 //defer tmp.cleanup();
11501156
1151 pipeToFileSystem(io, tmp.dir, &reader, .{
1157 extract(io, tmp.dir, &reader, .{
11521158 .strip_components = 1,
11531159 .exclude_empty_directories = true,
11541160 .mode_mode = opt,