Skip to content

Commit

Permalink
Allow empty dirs on tar
Browse files Browse the repository at this point in the history
  • Loading branch information
GabrielSimonetto committed Oct 2, 2021
1 parent 0c65fbd commit e352f8b
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/archive/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)?;
}
Expand Down
9 changes: 6 additions & 3 deletions tests/compress_empty_dir.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand All @@ -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);
Expand Down

0 comments on commit e352f8b

Please sign in to comment.