mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-08 04:25:31 +00:00
feat: use resolve_path instead clear_path in smart_unpack
This commit is contained in:
parent
8b84038cec
commit
77d999d33a
@ -14,11 +14,7 @@ use crate::{
|
|||||||
Extension,
|
Extension,
|
||||||
},
|
},
|
||||||
utils::{
|
utils::{
|
||||||
self,
|
self, io::lock_and_flush_output_stdio, is_path_stdin, logger::{info, info_accessible}, nice_directory_display, user_wants_to_continue
|
||||||
io::lock_and_flush_output_stdio,
|
|
||||||
is_path_stdin,
|
|
||||||
logger::{info, info_accessible},
|
|
||||||
nice_directory_display, user_wants_to_continue,
|
|
||||||
},
|
},
|
||||||
QuestionAction, QuestionPolicy, BUFFER_CAPACITY,
|
QuestionAction, QuestionPolicy, BUFFER_CAPACITY,
|
||||||
};
|
};
|
||||||
@ -309,7 +305,7 @@ fn smart_unpack(
|
|||||||
|
|
||||||
let root_contains_only_one_element = fs::read_dir(temp_dir_path)?.count() == 1;
|
let root_contains_only_one_element = fs::read_dir(temp_dir_path)?.count() == 1;
|
||||||
|
|
||||||
let (previous_path, new_path) = if root_contains_only_one_element {
|
let (previous_path, mut new_path) = if root_contains_only_one_element {
|
||||||
// Only one file in the root directory, so we can just move it to the output directory
|
// Only one file in the root directory, so we can just move it to the output directory
|
||||||
let file = fs::read_dir(temp_dir_path)?.next().expect("item exists")?;
|
let file = fs::read_dir(temp_dir_path)?.next().expect("item exists")?;
|
||||||
let file_path = file.path();
|
let file_path = file.path();
|
||||||
@ -323,10 +319,10 @@ fn smart_unpack(
|
|||||||
(temp_dir_path.to_owned(), output_file_path.to_owned())
|
(temp_dir_path.to_owned(), output_file_path.to_owned())
|
||||||
};
|
};
|
||||||
|
|
||||||
// Before moving, need to check if a file with the same name already exists
|
new_path = match utils::resolve_path(&new_path, question_policy)? {
|
||||||
if !utils::clear_path(&new_path, question_policy)? {
|
Some(path) => path,
|
||||||
return Ok(ControlFlow::Break(()));
|
None => return Ok(ControlFlow::Break(())),
|
||||||
}
|
};
|
||||||
|
|
||||||
// Rename the temporary directory to the archive name, which is output_file_path
|
// Rename the temporary directory to the archive name, which is output_file_path
|
||||||
fs::rename(&previous_path, &new_path)?;
|
fs::rename(&previous_path, &new_path)?;
|
||||||
|
@ -8,7 +8,7 @@ use std::{
|
|||||||
|
|
||||||
use fs_err as fs;
|
use fs_err as fs;
|
||||||
|
|
||||||
use super::user_wants_to_overwrite;
|
use super::{question::FileConflitOperation, user_wants_to_overwrite};
|
||||||
use crate::{
|
use crate::{
|
||||||
extension::Extension,
|
extension::Extension,
|
||||||
utils::{logger::info_accessible, EscapedPathDisplay},
|
utils::{logger::info_accessible, EscapedPathDisplay},
|
||||||
|
@ -18,10 +18,10 @@ pub use self::{
|
|||||||
EscapedPathDisplay,
|
EscapedPathDisplay,
|
||||||
},
|
},
|
||||||
fs::{
|
fs::{
|
||||||
cd_into_same_dir_as, clear_path, create_dir_if_non_existent, is_path_stdin, remove_file_or_dir,
|
cd_into_same_dir_as, resolve_path, create_dir_if_non_existent, is_path_stdin, remove_file_or_dir,
|
||||||
try_infer_extension, rename_for_available_filename
|
try_infer_extension, rename_for_available_filename
|
||||||
},
|
},
|
||||||
question::{ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy},
|
question::{ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, FileConflitOperation, QuestionAction, QuestionPolicy},
|
||||||
utf8::{get_invalid_utf8_paths, is_invalid_utf8},
|
utf8::{get_invalid_utf8_paths, is_invalid_utf8},
|
||||||
};
|
};
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user