mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
refactoring: Extract function (#116)
This commit is contained in:
parent
5f7d777342
commit
4404b91a23
@ -3,7 +3,6 @@
|
|||||||
use std::{
|
use std::{
|
||||||
env, fs,
|
env, fs,
|
||||||
io::{self, prelude::*},
|
io::{self, prelude::*},
|
||||||
path::Component,
|
|
||||||
path::{Path, PathBuf},
|
path::{Path, PathBuf},
|
||||||
};
|
};
|
||||||
|
|
||||||
@ -12,7 +11,7 @@ use zip::{self, read::ZipFile, ZipArchive};
|
|||||||
|
|
||||||
use crate::{
|
use crate::{
|
||||||
info, oof,
|
info, oof,
|
||||||
utils::{self, dir_is_empty, Bytes},
|
utils::{self, dir_is_empty, strip_cur_dir, Bytes},
|
||||||
};
|
};
|
||||||
|
|
||||||
use self::utf8::get_invalid_utf8_paths;
|
use self::utf8::get_invalid_utf8_paths;
|
||||||
@ -48,7 +47,7 @@ where
|
|||||||
fs::create_dir_all(&path)?;
|
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()));
|
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(())
|
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
|
/// Changes the process' current directory to the directory that contains the
|
||||||
/// file pointed to by `filename` and returns the directory that the process
|
/// file pointed to by `filename` and returns the directory that the process
|
||||||
/// was in before this function was called.
|
/// 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)))
|
Confirmation::new("Do you want to overwrite 'FILE'?", Some("FILE")).ask(Some(&to_utf(path)))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user