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 {...@@ -3,6 +3,8 @@ pub const Options = struct {
3 strip_components: u32 = 0,3 strip_components: u32 = 0,
4 /// How to handle the "mode" property of files from within the tar file.4 /// How to handle the "mode" property of files from within the tar file.
5 mode_mode: ModeMode = .executable_bit_only,5 mode_mode: ModeMode = .executable_bit_only,
6 /// Prevents creation of empty directories.
7 exclude_empty_directories: bool = false,
6 /// Provide this to receive detailed error messages.8 /// Provide this to receive detailed error messages.
7 /// When this is provided, some errors which would otherwise be returned immediately9 /// When this is provided, some errors which would otherwise be returned immediately
8 /// will instead be added to this structure. The API user must check the errors10 /// 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...@@ -201,7 +203,7 @@ pub fn pipeToFileSystem(dir: std.fs.Dir, reader: anytype, options: Options) !voi
201 switch (header.fileType()) {203 switch (header.fileType()) {
202 .directory => {204 .directory => {
203 const file_name = try stripComponents(unstripped_file_name, options.strip_components);205 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) {
205 try dir.makePath(file_name);207 try dir.makePath(file_name);
206 }208 }
207 },209 },