From 40029d6875ce297406b573d78d11b0d00107cab6 Mon Sep 17 00:00:00 2001 From: Travis Staloch Date: Sun, 9 Apr 2023 16:05:17 -0700 Subject: [PATCH] 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. --- lib/std/tar.zig | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/lib/std/tar.zig b/lib/std/tar.zig index 91772d7319..ec668d5f93 100644 --- a/lib/std/tar.zig +++ b/lib/std/tar.zig @@ -35,7 +35,7 @@ pub const Header = struct { pub fn fileSize(header: Header) !u64 { const raw = header.bytes[124..][0..12]; const ltrimmed = std.mem.trimLeft(u8, raw, "0"); - const rtrimmed = std.mem.trimRight(u8, ltrimmed, "\x00"); + const rtrimmed = std.mem.trimRight(u8, ltrimmed, " \x00"); if (rtrimmed.len == 0) return 0; return std.fmt.parseInt(u64, rtrimmed, 8); } @@ -122,13 +122,16 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi .directory => { const file_name = try stripComponents(unstripped_file_name, options.strip_components); if (file_name.len != 0) { - try dir.makeDir(file_name); + try dir.makePath(file_name); } }, .normal => { if (file_size == 0 and unstripped_file_name.len == 0) return; const file_name = try stripComponents(unstripped_file_name, options.strip_components); + if (std.fs.path.dirname(file_name)) |dir_name| { + try dir.makePath(dir_name); + } var file = try dir.createFile(file_name, .{}); defer file.close();