Minor renaming

This commit is contained in:
João M. Bezerra 2021-08-13 02:14:28 -03:00
parent 8f7f812e87
commit c9d4eea403
5 changed files with 33 additions and 35 deletions

View File

@ -22,8 +22,7 @@ pub fn unpack_archive(
let mut file = file?;
let file_path = output_folder.join(file.path()?);
if file_path.exists() && !utils::permission_for_overwriting(&file_path, flags)? {
// The user does not want to overwrite the file
if file_path.exists() && !utils::user_wants_to_overwrite(&file_path, flags)? {
continue;
}

View File

@ -12,28 +12,6 @@ use crate::{
utils::{self, colors},
};
#[cfg(unix)]
fn __unix_set_permissions(file_path: &Path, file: &ZipFile) {
use std::os::unix::fs::PermissionsExt;
if let Some(mode) = file.unix_mode() {
fs::set_permissions(&file_path, fs::Permissions::from_mode(mode)).unwrap();
}
}
fn check_for_comments(file: &ZipFile) {
let comment = file.comment();
if !comment.is_empty() {
println!(
"{}[INFO]{} Comment in {}: {}",
colors::yellow(),
colors::reset(),
file.name(),
comment
);
}
}
pub fn unpack_archive<R>(
mut archive: ZipArchive<R>,
into: &Path,
@ -51,8 +29,7 @@ where
};
let file_path = into.join(file_path);
if file_path.exists() && !utils::permission_for_overwriting(&file_path, flags)? {
// The user does not want to overwrite the file
if file_path.exists() && !utils::user_wants_to_overwrite(&file_path, flags)? {
continue;
}
@ -142,3 +119,25 @@ where
let bytes = writer.finish()?;
Ok(bytes)
}
fn check_for_comments(file: &ZipFile) {
let comment = file.comment();
if !comment.is_empty() {
println!(
"{}[INFO]{} Comment in {}: {}",
colors::yellow(),
colors::reset(),
file.name(),
comment
);
}
}
#[cfg(unix)]
fn __unix_set_permissions(file_path: &Path, file: &ZipFile) {
use std::os::unix::fs::PermissionsExt;
if let Some(mode) = file.unix_mode() {
fs::set_permissions(&file_path, fs::Permissions::from_mode(mode)).unwrap();
}
}

View File

@ -89,8 +89,7 @@ pub fn run(command: Command, flags: &oof::Flags) -> crate::Result<()> {
.display_and_crash();
}
if output_path.exists() && !utils::permission_for_overwriting(&output_path, flags)? {
// The user does not want to overwrite the file
if output_path.exists() && !utils::user_wants_to_overwrite(&output_path, flags)? {
return Ok(());
}

View File

@ -10,14 +10,11 @@ mod error;
mod extension;
mod utils;
use dialogs::Confirmation;
pub use error::{Error, Result};
pub const EXIT_FAILURE: i32 = 127;
const VERSION: &str = "0.1.5";
const OVERWRITE_CONFIRMATION: Confirmation =
Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE"));
fn help_command() {
use utils::colors::*;
@ -76,5 +73,5 @@ Visit https://github.com/vrmiguel/ouch for more usage examples.",
#[inline]
fn version_command() {
use utils::colors::*;
println!("{green}ouch{reset} {}", crate::VERSION, green = green(), reset = reset(),);
println!("{green}ouch{reset} {}", crate::VERSION, green = green(), reset = reset());
}

View File

@ -5,7 +5,7 @@ use std::{
path::{Path, PathBuf},
};
use crate::{oof, OVERWRITE_CONFIRMATION};
use crate::{dialogs::Confirmation, oof};
pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> {
if !path.exists() {
@ -42,7 +42,7 @@ pub fn cd_into_same_dir_as(filename: &Path) -> crate::Result<PathBuf> {
Ok(previous_location)
}
pub fn permission_for_overwriting(path: &Path, flags: &oof::Flags) -> crate::Result<bool> {
pub fn user_wants_to_overwrite(path: &Path, flags: &oof::Flags) -> crate::Result<bool> {
match (flags.is_present("yes"), flags.is_present("no")) {
(true, true) => {
unreachable!(
@ -55,7 +55,11 @@ pub fn permission_for_overwriting(path: &Path, flags: &oof::Flags) -> crate::Res
}
let file_path_str = to_utf(path);
OVERWRITE_CONFIRMATION.ask(Some(&file_path_str))
const OVERWRITE_CONFIRMATION_QUESTION: Confirmation =
Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE"));
OVERWRITE_CONFIRMATION_QUESTION.ask(Some(&file_path_str))
}
pub fn to_utf(os_str: impl AsRef<OsStr>) -> String {