Skip to content

Commit 64f6afe

Browse files
committed
optimize tar archive
1 parent 0cf2f52 commit 64f6afe

File tree

1 file changed

+14
-17
lines changed

1 file changed

+14
-17
lines changed

src/lib.rs

Lines changed: 14 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -964,7 +964,7 @@ pub fn archive(paths: &ExePaths, quiet: bool, cpus: usize, password: &str, exlud
964964

965965
for input_path in input_paths {
966966
let input_path_obj = Path::new(input_path);
967-
let file_name = Path::file_name(input_path_obj).unwrap().to_str().unwrap();
967+
let file_name = input_path_obj.file_name().unwrap().to_str().unwrap();
968968

969969
let mut cmd = cmd.clone();
970970

@@ -995,6 +995,8 @@ pub fn archive(paths: &ExePaths, quiet: bool, cpus: usize, password: &str, exlud
995995
result
996996
}
997997
ArchiveFormat::Tar => {
998+
let mut input_paths_vec = Vec::<String>::new();
999+
9981000
let mut cmd = vec![paths.tar_path.as_str(), "-r"];
9991001

10001002
if !quiet {
@@ -1011,28 +1013,23 @@ pub fn archive(paths: &ExePaths, quiet: bool, cpus: usize, password: &str, exlud
10111013
}
10121014
}
10131015

1014-
let mut es = 0;
1015-
10161016
for input_path in input_paths {
10171017
let input_path_obj = Path::new(input_path);
1018-
let file_name = Path::file_name(input_path_obj).unwrap().to_str().unwrap();
1019-
1020-
let mut cmd = cmd.clone();
1021-
1022-
cmd.push(file_name);
1023-
10241018
let input_folder = input_path_obj.parent().unwrap().to_str().unwrap();
1019+
let file_name = input_path_obj.file_name().unwrap().to_str().unwrap();
10251020

1026-
es = match execute_one(&cmd, input_folder) {
1027-
Ok(es) => es,
1028-
Err(error) => {
1029-
try_delete_file(output_path);
1030-
return Err(error);
1031-
}
1032-
}
1021+
input_paths_vec.push(String::from("-C"));
1022+
input_paths_vec.push(String::from(input_folder));
1023+
input_paths_vec.push(String::from(file_name));
1024+
}
1025+
1026+
for input_path in &input_paths_vec {
1027+
cmd.push(&input_path);
10331028
}
10341029

1035-
Ok(es)
1030+
let output_folder = output_path_obj.parent().unwrap().to_str().unwrap();
1031+
1032+
execute_one(&cmd, output_folder)
10361033
}
10371034
ArchiveFormat::Z => {
10381035
// Not recommend

0 commit comments

Comments
 (0)