Skip to content

Commit

Permalink
Allow empty dirs on zip
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSimonetto committed Oct 2, 2021
1 parent f477176 commit b1acedc
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/archive/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -91,14 +91,16 @@ where
let path = entry.path();

if path.is_dir() {
continue;
if dir_is_empty(path)? {
writer.add_directory(path.to_str().unwrap().to_owned(), options)?;
}
// If a dir has files, the files are responsible for creating them.
} else {
writer.start_file(path.to_str().unwrap().to_owned(), options)?;
// TODO: better error messages
let file_bytes = fs::read(entry.path())?;
writer.write_all(&*file_bytes)?;
}

writer.start_file(path.to_str().unwrap().to_owned(), options)?;

// TODO: better error messages
let file_bytes = fs::read(entry.path())?;
writer.write_all(&*file_bytes)?;
}

env::set_current_dir(previous_location)?;
Expand All @@ -115,6 +117,10 @@ fn check_for_comments(file: &ZipFile) {
}
}

fn dir_is_empty(dir_path: &Path) -> crate::Result<bool> {
Ok(dir_path.read_dir()?.next().is_none())
}

#[cfg(unix)]
fn __unix_set_permissions(file_path: &Path, file: &ZipFile) -> crate::Result<()> {
use std::os::unix::fs::PermissionsExt;
Expand Down

0 comments on commit b1acedc

Please sign in to comment.