mirror of
https://github.com/ouch-org/ouch.git
synced 2025-07-22 09:30:15 +00:00
Change clear_path
to return Result<bool>
So `Ok(true)` means the path is clear while `Ok(false)` means the user doesn't want to overwrite
This commit is contained in:
parent
d1d781dded
commit
c33d896743
@ -31,7 +31,7 @@ pub fn unpack_archive(
|
||||
let mut file = file?;
|
||||
|
||||
let file_path = output_folder.join(file.path()?);
|
||||
if utils::clear_path(&file_path, question_policy)?.is_none() {
|
||||
if !utils::clear_path(&file_path, question_policy)? {
|
||||
// User doesn't want to overwrite
|
||||
continue;
|
||||
}
|
||||
|
@ -39,7 +39,7 @@ where
|
||||
};
|
||||
|
||||
let file_path = into.join(file_path);
|
||||
if clear_path(&file_path, question_policy)?.is_none() {
|
||||
if !clear_path(&file_path, question_policy)? {
|
||||
// User doesn't want to overwrite
|
||||
continue;
|
||||
}
|
||||
|
@ -342,7 +342,7 @@ fn decompress_file(
|
||||
//
|
||||
// Any other Zip decompression done can take up the whole RAM and freeze ouch.
|
||||
if formats.len() == 1 && *formats[0].compression_formats == [Zip] {
|
||||
if utils::clear_path(output_dir, question_policy)?.is_none() {
|
||||
if !utils::clear_path(output_dir, question_policy)? {
|
||||
// User doesn't want to overwrite
|
||||
return Ok(());
|
||||
}
|
||||
@ -374,7 +374,7 @@ fn decompress_file(
|
||||
reader = chain_reader_decoder(format, reader)?;
|
||||
}
|
||||
|
||||
if utils::clear_path(&output_path, question_policy)?.is_none() {
|
||||
if !utils::clear_path(&output_path, question_policy)? {
|
||||
// User doesn't want to overwrite
|
||||
return Ok(());
|
||||
}
|
||||
|
@ -19,14 +19,14 @@ pub fn dir_is_empty(dir_path: &Path) -> bool {
|
||||
dir_path.read_dir().map(is_empty).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Remove `path` asking the user to overwrite if necessary
|
||||
/// `Ok(Some(())` means the path is clear,
|
||||
/// `Ok(None)` means the user doesn't want to overwrite
|
||||
/// `Err(_)` is an error
|
||||
// ToDo: Actual type to translate the above might be clearer?
|
||||
pub fn clear_path(path: &Path, question_policy: QuestionPolicy) -> crate::Result<Option<()>> {
|
||||
/// Remove `path` asking the user to overwrite if necessary.
|
||||
///
|
||||
/// * `Ok(true)` means the path is clear,
|
||||
/// * `Ok(false)` means the user doesn't want to overwrite
|
||||
/// * `Err(_)` is an error
|
||||
pub fn clear_path(path: &Path, question_policy: QuestionPolicy) -> crate::Result<bool> {
|
||||
if path.exists() && !user_wants_to_overwrite(path, question_policy)? {
|
||||
return Ok(None);
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
if path.is_dir() {
|
||||
@ -35,7 +35,7 @@ pub fn clear_path(path: &Path, question_policy: QuestionPolicy) -> crate::Result
|
||||
fs::remove_file(path)?;
|
||||
}
|
||||
|
||||
Ok(Some(()))
|
||||
Ok(true)
|
||||
}
|
||||
|
||||
/// Creates a directory at the path, if there is nothing there.
|
||||
|
Loading…
x
Reference in New Issue
Block a user