From 51e15a9650d4634d7d228617fc2aea3ecc2ed073 Mon Sep 17 00:00:00 2001 From: Andrew Kelley Date: Tue, 3 Oct 2023 23:25:04 -0700 Subject: std.tar: add option for omitting empty directories --- lib/std/tar.zig | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'lib/std/tar.zig') diff --git a/lib/std/tar.zig b/lib/std/tar.zig index b71c118d52..9ed69730aa 100644 --- a/lib/std/tar.zig +++ b/lib/std/tar.zig @@ -3,6 +3,8 @@ pub const Options = struct { strip_components: u32 = 0, /// How to handle the "mode" property of files from within the tar file. mode_mode: ModeMode = .executable_bit_only, + /// Prevents creation of empty directories. + exclude_empty_directories: bool = false, /// 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 @@ -201,7 +203,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi switch (header.fileType()) { .directory => { const file_name = try stripComponents(unstripped_file_name, options.strip_components); - if (file_name.len != 0) { + if (file_name.len != 0 and !options.exclude_empty_directories) { try dir.makePath(file_name); } }, -- cgit v1.2.3