diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 6db5d00..e25e7f5 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -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 { + 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;