mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 20:15:27 +00:00
Move utf8 utils from zip.rs to utils module
This commit is contained in:
parent
ed0e225219
commit
f1c0c82323
@ -170,25 +170,3 @@ fn __unix_set_permissions(file_path: &Path, file: &ZipFile) -> crate::Result<()>
|
|||||||
|
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
|
|
||||||
mod utf8 {
|
|
||||||
use std::path::{Path, PathBuf};
|
|
||||||
|
|
||||||
fn is_invalid_utf8(path: &Path) -> bool {
|
|
||||||
#[cfg(unix)]
|
|
||||||
{
|
|
||||||
use std::{os::unix::prelude::OsStrExt, str};
|
|
||||||
|
|
||||||
let bytes = path.as_os_str().as_bytes();
|
|
||||||
str::from_utf8(bytes).is_err()
|
|
||||||
}
|
|
||||||
#[cfg(not(unix))]
|
|
||||||
{
|
|
||||||
path.to_str().is_none()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec<PathBuf> {
|
|
||||||
paths.iter().filter_map(|path| is_invalid_utf8(&path).then(|| path.clone())).collect()
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
@ -13,3 +13,26 @@ pub use fs::{cd_into_same_dir_as, create_dir_if_non_existent, dir_is_empty, try_
|
|||||||
pub use question::{
|
pub use question::{
|
||||||
create_or_ask_overwrite, user_wants_to_continue_decompressing, user_wants_to_overwrite, QuestionPolicy,
|
create_or_ask_overwrite, user_wants_to_continue_decompressing, user_wants_to_overwrite, QuestionPolicy,
|
||||||
};
|
};
|
||||||
|
pub use utf8::{get_invalid_utf8_paths, is_invalid_utf8};
|
||||||
|
|
||||||
|
mod utf8 {
|
||||||
|
use std::path::{Path, PathBuf};
|
||||||
|
|
||||||
|
pub fn is_invalid_utf8(path: &Path) -> bool {
|
||||||
|
#[cfg(unix)]
|
||||||
|
{
|
||||||
|
use std::{os::unix::prelude::OsStrExt, str};
|
||||||
|
|
||||||
|
let bytes = path.as_os_str().as_bytes();
|
||||||
|
str::from_utf8(bytes).is_err()
|
||||||
|
}
|
||||||
|
#[cfg(not(unix))]
|
||||||
|
{
|
||||||
|
path.to_str().is_none()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn get_invalid_utf8_paths(paths: &[PathBuf]) -> Vec<PathBuf> {
|
||||||
|
paths.iter().filter_map(|path| is_invalid_utf8(&path).then(|| path.clone())).collect()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user