diff --git a/src/archive/tar.rs b/src/archive/tar.rs index 010bb45..8dc5d1e 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -51,7 +51,9 @@ where let path = entry.path(); println!("Compressing '{}'.", utils::to_utf(path)); - if !path.is_dir() { + if path.is_dir() { + builder.append_dir(path, path)?; + } else { let mut file = fs::File::open(path)?; builder.append_file(path, &mut file)?; } diff --git a/tests/compress_empty_dir.rs b/tests/compress_empty_dir.rs index 4a7c108..95f3348 100644 --- a/tests/compress_empty_dir.rs +++ b/tests/compress_empty_dir.rs @@ -5,7 +5,12 @@ use std::{env, path::PathBuf}; use utils::*; #[test] -fn test_compress_decompress_with_empty_dir() { +fn test_each_format() { + test_compress_decompress_with_empty_dir("tar"); + test_compress_decompress_with_empty_dir("zip"); +} + +fn test_compress_decompress_with_empty_dir(format: &str) { // System temporary directory depends on the platform, for linux it's /tmp let system_tmp = env::temp_dir(); @@ -19,8 +24,6 @@ fn test_compress_decompress_with_empty_dir() { let mut file_paths: Vec = vec![empty_dir_path]; - let format = "zip"; - let compressed_archive_path: PathBuf = compress_files(&testing_dir_path, &file_paths, &format); let mut extracted_paths = extract_files(&compressed_archive_path);