Allow empty dirs on zip

This commit is contained in:
Gabriel Simonetto 2021-10-02 17:10:42 -03:00
parent d43a93d8bb
commit 0c65fbd2d4

View File

@ -88,14 +88,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)?;
@ -112,6 +114,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;