mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-06 11:35:45 +00:00
refactoring: Extract function (#116)
This commit is contained in:
parent
5f7d777342
commit
4404b91a23
@ -3,7 +3,6 @@
|
||||
use std::{
|
||||
env, fs,
|
||||
io::{self, prelude::*},
|
||||
path::Component,
|
||||
path::{Path, PathBuf},
|
||||
};
|
||||
|
||||
@ -12,7 +11,7 @@ use zip::{self, read::ZipFile, ZipArchive};
|
||||
|
||||
use crate::{
|
||||
info, oof,
|
||||
utils::{self, dir_is_empty, Bytes},
|
||||
utils::{self, dir_is_empty, strip_cur_dir, Bytes},
|
||||
};
|
||||
|
||||
use self::utf8::get_invalid_utf8_paths;
|
||||
@ -48,7 +47,7 @@ where
|
||||
fs::create_dir_all(&path)?;
|
||||
}
|
||||
}
|
||||
let file_path = file_path.strip_prefix(Component::CurDir).unwrap_or_else(|_| file_path.as_path());
|
||||
let file_path = strip_cur_dir(file_path.as_path());
|
||||
|
||||
info!("{:?} extracted. ({})", file_path.display(), Bytes::new(file.size()));
|
||||
|
||||
|
@ -23,6 +23,13 @@ pub fn create_dir_if_non_existent(path: &Path) -> crate::Result<()> {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn strip_cur_dir(source_path: &Path) -> PathBuf {
|
||||
source_path
|
||||
.strip_prefix(Component::CurDir)
|
||||
.map(|path| path.to_path_buf())
|
||||
.unwrap_or_else(|_| source_path.to_path_buf())
|
||||
}
|
||||
|
||||
/// Changes the process' current directory to the directory that contains the
|
||||
/// file pointed to by `filename` and returns the directory that the process
|
||||
/// was in before this function was called.
|
||||
@ -46,7 +53,7 @@ pub fn user_wants_to_overwrite(path: &Path, flags: &oof::Flags) -> crate::Result
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let path = path.strip_prefix(Component::CurDir).unwrap_or_else(|_| path);
|
||||
let path = strip_cur_dir(path);
|
||||
Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&to_utf(path)))
|
||||
}
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user