diff --git a/src/decompressors/tar.rs b/src/decompressors/tar.rs index 272b9b2..ef5086e 100644 --- a/src/decompressors/tar.rs +++ b/src/decompressors/tar.rs @@ -35,11 +35,11 @@ impl TarDecompressor { let mut file = file?; let file_path = PathBuf::from(into).join(file.path()?); - if file_path.exists() { - if !utils::permission_for_overwriting(&file_path, flags, &confirm)? { - // The user does not want to overwrite the file - continue; - } + if file_path.exists() + && !utils::permission_for_overwriting(&file_path, flags, &confirm)? + { + // The user does not want to overwrite the file + continue; } file.unpack_in(into)?; diff --git a/src/decompressors/zip.rs b/src/decompressors/zip.rs index 3c4a5a4..fb81341 100644 --- a/src/decompressors/zip.rs +++ b/src/decompressors/zip.rs @@ -11,7 +11,7 @@ use super::decompressor::{DecompressionResult, Decompressor}; use crate::{cli::Flags, dialogs::Confirmation, file::File, utils}; #[cfg(unix)] -fn __unix_set_permissions(file_path: &PathBuf, file: &ZipFile) { +fn __unix_set_permissions(file_path: &Path, file: &ZipFile) { use std::os::unix::fs::PermissionsExt; if let Some(mode) = file.unix_mode() { @@ -52,11 +52,11 @@ impl ZipDecompressor { }; let file_path = into.join(file_path); - if file_path.exists() { - if !utils::permission_for_overwriting(&file_path, flags, &confirm)? { - // The user does not want to overwrite the file - continue; - } + if file_path.exists() + && !utils::permission_for_overwriting(&file_path, flags, &confirm)? + { + // The user does not want to overwrite the file + continue; } Self::check_for_comments(&file); diff --git a/src/evaluator.rs b/src/evaluator.rs index 105ed26..4775e26 100644 --- a/src/evaluator.rs +++ b/src/evaluator.rs @@ -162,11 +162,11 @@ impl Evaluator { // TODO: use -y and -n here let output_path = output.path.clone(); - if output_path.exists() { - if !utils::permission_for_overwriting(&output_path, flags, &confirm)? { - // The user does not want to overwrite the file - return Ok(()); - } + if output_path.exists() + && !utils::permission_for_overwriting(&output_path, flags, &confirm)? + { + // The user does not want to overwrite the file + return Ok(()); } let bytes = match first_compressor { diff --git a/src/utils.rs b/src/utils.rs index c131fce..4e8a565 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -59,7 +59,7 @@ pub(crate) fn get_destination_path(dest: &Option) -> &Path { } } -pub(crate) fn change_dir_and_return_parent(filename: &PathBuf) -> crate::Result { +pub(crate) fn change_dir_and_return_parent(filename: &Path) -> crate::Result { let previous_location = env::current_dir()?; let parent = if let Some(parent) = filename.parent() { @@ -73,7 +73,7 @@ pub(crate) fn change_dir_and_return_parent(filename: &PathBuf) -> crate::Result< } pub fn permission_for_overwriting( - path: &PathBuf, + path: &Path, flags: Flags, confirm: &Confirmation, ) -> crate::Result { @@ -83,6 +83,6 @@ pub fn permission_for_overwriting( Flags::None => {} } - let file_path_str = &*path.as_path().to_string_lossy(); - Ok(confirm.ask(Some(file_path_str))?) + let file_path_str = path.to_string_lossy(); + confirm.ask(Some(&file_path_str)) }