authorgravatar for twostepted@gmail.comTravis Staloch <twostepted@gmail.com> 2023-04-09 16:05:17-07:00
committergravatar for git@vexu.euVeikka Tuominen <git@vexu.eu> 2023-04-23 20:39:28+03:00
log40029d6875ce297406b573d78d11b0d00107cab6
treeaaf8efc5751477d0a62d23879e5be13241837a70
parent284c7b22a85a6a915740be826e66f91a4cbc743e

std.tar: make sub dirs + trim spaces

closes #15222. these changes allow the .tgz from this issue to decompress and the test code to succeed.

1 files changed, 5 insertions(+), 2 deletions(-)

lib/std/tar.zig+5-2
...@@ -35,7 +35,7 @@ pub const Header = struct {...@@ -35,7 +35,7 @@ pub const Header = struct {
35 pub fn fileSize(header: Header) !u64 {35 pub fn fileSize(header: Header) !u64 {
36 const raw = header.bytes[124..][0..12];36 const raw = header.bytes[124..][0..12];
37 const ltrimmed = std.mem.trimLeft(u8, raw, "0");37 const ltrimmed = std.mem.trimLeft(u8, raw, "0");
38 const rtrimmed = std.mem.trimRight(u8, ltrimmed, "\x00");38 const rtrimmed = std.mem.trimRight(u8, ltrimmed, " \x00");
39 if (rtrimmed.len == 0) return 0;39 if (rtrimmed.len == 0) return 0;
40 return std.fmt.parseInt(u64, rtrimmed, 8);40 return std.fmt.parseInt(u64, rtrimmed, 8);
41 }41 }
...@@ -122,13 +122,16 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi...@@ -122,13 +122,16 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
122 .directory => {122 .directory => {
123 const file_name = try stripComponents(unstripped_file_name, options.strip_components);123 const file_name = try stripComponents(unstripped_file_name, options.strip_components);
124 if (file_name.len != 0) {124 if (file_name.len != 0) {
125 try dir.makeDir(file_name);125 try dir.makePath(file_name);
126 }126 }
127 },127 },
128 .normal => {128 .normal => {
129 if (file_size == 0 and unstripped_file_name.len == 0) return;129 if (file_size == 0 and unstripped_file_name.len == 0) return;
130 const file_name = try stripComponents(unstripped_file_name, options.strip_components);130 const file_name = try stripComponents(unstripped_file_name, options.strip_components);
131131
132 if (std.fs.path.dirname(file_name)) |dir_name| {
133 try dir.makePath(dir_name);
134 }
132 var file = try dir.createFile(file_name, .{});135 var file = try dir.createFile(file_name, .{});
133 defer file.close();136 defer file.close();
134137