Allow empty dirs on tar

This commit is contained in:
Gabriel Simonetto 2021-10-02 17:33:16 -03:00
parent 0c65fbd2d4
commit e352f8bc93
2 changed files with 9 additions and 4 deletions

View File

@ -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)?;
}

View File

@ -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<PathBuf> = 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);