Skip to content

Commit aaaf2c5

Browse files
committed
std.tar: add option for omitting empty directories
1 parent d68f39b commit aaaf2c5

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

lib/std/tar.zig

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
},

0 commit comments

Comments
 (0)