mirror of
https://github.com/ziglang/zig.git
synced 2026-10-14 10:27:43 -04:00
std.tar: fix broken public interface
This commit is contained in:
1 parent
c4868b2bbc
commit
0cca7e732e
2 files changed
+48
-52
No files matched your search
+47
-51
@@ -21,6 +21,50 @@ const testing = std.testing;
|
|||||||
|
|
||||||
pub const output = @import("tar/output.zig");
|
pub const output = @import("tar/output.zig");
|
||||||
|
|
||||||
|
/// Provide this to receive detailed error messages.
|
||||||
|
/// When this is provided, some errors which would otherwise be returned
|
||||||
|
/// immediately will instead be added to this structure. The API user must check
|
||||||
|
/// the errors in diagnostics to know whether the operation succeeded or failed.
|
||||||
|
pub const Diagnostics = struct {
|
||||||
|
allocator: std.mem.Allocator,
|
||||||
|
errors: std.ArrayListUnmanaged(Error) = .{},
|
||||||
|
|
||||||
|
pub const Error = union(enum) {
|
||||||
|
unable_to_create_sym_link: struct {
|
||||||
|
code: anyerror,
|
||||||
|
file_name: []const u8,
|
||||||
|
link_name: []const u8,
|
||||||
|
},
|
||||||
|
unable_to_create_file: struct {
|
||||||
|
code: anyerror,
|
||||||
|
file_name: []const u8,
|
||||||
|
},
|
||||||
|
unsupported_file_type: struct {
|
||||||
|
file_name: []const u8,
|
||||||
|
file_type: Header.Kind,
|
||||||
|
},
|
||||||
|
};
|
||||||
|
|
||||||
|
pub fn deinit(d: *Diagnostics) void {
|
||||||
|
for (d.errors.items) |item| {
|
||||||
|
switch (item) {
|
||||||
|
.unable_to_create_sym_link => |info| {
|
||||||
|
d.allocator.free(info.file_name);
|
||||||
|
d.allocator.free(info.link_name);
|
||||||
|
},
|
||||||
|
.unable_to_create_file => |info| {
|
||||||
|
d.allocator.free(info.file_name);
|
||||||
|
},
|
||||||
|
.unsupported_file_type => |info| {
|
||||||
|
d.allocator.free(info.file_name);
|
||||||
|
},
|
||||||
|
}
|
||||||
|
}
|
||||||
|
d.errors.deinit(d.allocator);
|
||||||
|
d.* = undefined;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
/// pipeToFileSystem options
|
/// pipeToFileSystem options
|
||||||
pub const PipeOptions = struct {
|
pub const PipeOptions = struct {
|
||||||
/// Number of directory levels to skip when extracting files.
|
/// Number of directory levels to skip when extracting files.
|
||||||
@@ -29,10 +73,7 @@ pub const PipeOptions = struct {
|
|||||||
mode_mode: ModeMode = .executable_bit_only,
|
mode_mode: ModeMode = .executable_bit_only,
|
||||||
/// Prevents creation of empty directories.
|
/// Prevents creation of empty directories.
|
||||||
exclude_empty_directories: bool = false,
|
exclude_empty_directories: bool = false,
|
||||||
/// Provide this to receive detailed error messages.
|
/// Collects error messages during unpacking
|
||||||
/// When this is provided, some errors which would otherwise be returned immediately
|
|
||||||
/// will instead be added to this structure. The API user must check the errors
|
|
||||||
/// in diagnostics to know whether the operation succeeded or failed.
|
|
||||||
diagnostics: ?*Diagnostics = null,
|
diagnostics: ?*Diagnostics = null,
|
||||||
|
|
||||||
pub const ModeMode = enum {
|
pub const ModeMode = enum {
|
||||||
@@ -44,46 +85,6 @@ pub const PipeOptions = struct {
|
|||||||
/// Other bits of the mode are left as the default when creating files.
|
/// Other bits of the mode are left as the default when creating files.
|
||||||
executable_bit_only,
|
executable_bit_only,
|
||||||
};
|
};
|
||||||
|
|
||||||
pub const Diagnostics = struct {
|
|
||||||
allocator: std.mem.Allocator,
|
|
||||||
errors: std.ArrayListUnmanaged(Error) = .{},
|
|
||||||
|
|
||||||
pub const Error = union(enum) {
|
|
||||||
unable_to_create_sym_link: struct {
|
|
||||||
code: anyerror,
|
|
||||||
file_name: []const u8,
|
|
||||||
link_name: []const u8,
|
|
||||||
},
|
|
||||||
unable_to_create_file: struct {
|
|
||||||
code: anyerror,
|
|
||||||
file_name: []const u8,
|
|
||||||
},
|
|
||||||
unsupported_file_type: struct {
|
|
||||||
file_name: []const u8,
|
|
||||||
file_type: Header.Kind,
|
|
||||||
},
|
|
||||||
};
|
|
||||||
|
|
||||||
pub fn deinit(d: *Diagnostics) void {
|
|
||||||
for (d.errors.items) |item| {
|
|
||||||
switch (item) {
|
|
||||||
.unable_to_create_sym_link => |info| {
|
|
||||||
d.allocator.free(info.file_name);
|
|
||||||
d.allocator.free(info.link_name);
|
|
||||||
},
|
|
||||||
.unable_to_create_file => |info| {
|
|
||||||
d.allocator.free(info.file_name);
|
|
||||||
},
|
|
||||||
.unsupported_file_type => |info| {
|
|
||||||
d.allocator.free(info.file_name);
|
|
||||||
},
|
|
||||||
}
|
|
||||||
}
|
|
||||||
d.errors.deinit(d.allocator);
|
|
||||||
d.* = undefined;
|
|
||||||
}
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const Header = struct {
|
const Header = struct {
|
||||||
@@ -246,13 +247,8 @@ pub const IteratorOptions = struct {
|
|||||||
file_name_buffer: []u8,
|
file_name_buffer: []u8,
|
||||||
/// Use a buffer with length `std.fs.MAX_PATH_BYTES` to match file system capabilities.
|
/// Use a buffer with length `std.fs.MAX_PATH_BYTES` to match file system capabilities.
|
||||||
link_name_buffer: []u8,
|
link_name_buffer: []u8,
|
||||||
/// Provide this to receive detailed error messages.
|
/// Collects error messages during unpacking
|
||||||
/// When this is provided, some errors which would otherwise be returned immediately
|
|
||||||
/// will instead be added to this structure. The API user must check the errors
|
|
||||||
/// in diagnostics to know whether the operation succeeded or failed.
|
|
||||||
diagnostics: ?*Diagnostics = null,
|
diagnostics: ?*Diagnostics = null,
|
||||||
|
|
||||||
pub const Diagnostics = PipeOptions.Diagnostics;
|
|
||||||
};
|
};
|
||||||
|
|
||||||
/// Iterates over files in tar archive.
|
/// Iterates over files in tar archive.
|
||||||
@@ -277,7 +273,7 @@ pub const FileKind = enum {
|
|||||||
pub fn Iterator(comptime ReaderType: type) type {
|
pub fn Iterator(comptime ReaderType: type) type {
|
||||||
return struct {
|
return struct {
|
||||||
reader: ReaderType,
|
reader: ReaderType,
|
||||||
diagnostics: ?*PipeOptions.Diagnostics = null,
|
diagnostics: ?*Diagnostics = null,
|
||||||
|
|
||||||
// buffers for heeader and file attributes
|
// buffers for heeader and file attributes
|
||||||
header_buffer: [Header.SIZE]u8 = undefined,
|
header_buffer: [Header.SIZE]u8 = undefined,
|
||||||
|
|||||||
@@ -1147,7 +1147,7 @@ fn unpackTarball(f: *Fetch, out_dir: fs.Dir, reader: anytype) RunError!void {
|
|||||||
const eb = &f.error_bundle;
|
const eb = &f.error_bundle;
|
||||||
const gpa = f.arena.child_allocator;
|
const gpa = f.arena.child_allocator;
|
||||||
|
|
||||||
var diagnostics: std.tar.Options.Diagnostics = .{ .allocator = gpa };
|
var diagnostics: std.tar.Diagnostics = .{ .allocator = gpa };
|
||||||
defer diagnostics.deinit();
|
defer diagnostics.deinit();
|
||||||
|
|
||||||
std.tar.pipeToFileSystem(out_dir, reader, .{
|
std.tar.pipeToFileSystem(out_dir, reader, .{
|
||||||
|
|||||||
Reference in new issue
Block a user