authorgravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-03 23:25:04-07:00
committergravatar for andrew@ziglang.orgAndrew Kelley <andrew@ziglang.org> 2023-10-08 16:54:30-07:00
log51e15a9650d4634d7d228617fc2aea3ecc2ed073
tree816f164fc083cce2817be4fda9cfdce473867816
parent54e7f58fcb8cd3fbfd1b1a3efd090c296b0e728b

std.tar: add option for omitting empty directories


1 files changed, 3 insertions(+), 1 deletions(-)

lib/std/tar.zig+3-1
......@@ -3,6 +3,8 @@ pub const Options = struct {
33 strip_components: u32 = 0,
44 /// How to handle the "mode" property of files from within the tar file.
55 mode_mode: ModeMode = .executable_bit_only,
6 /// Prevents creation of empty directories.
7 exclude_empty_directories: bool = false,
68 /// Provide this to receive detailed error messages.
79 /// When this is provided, some errors which would otherwise be returned immediately
810 /// will instead be added to this structure. The API user must check the errors
......@@ -201,7 +203,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
201203 switch (header.fileType()) {
202204 .directory => {
203205 const file_name = try stripComponents(unstripped_file_name, options.strip_components);
204 if (file_name.len != 0) {
206 if (file_name.len != 0 and !options.exclude_empty_directories) {
205207 try dir.makePath(file_name);
206208 }
207209 },