mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-07 12:05:46 +00:00
chore: simplify code after feature stabilization
no need to reimplement `Path::is_symlink` anymore
This commit is contained in:
parent
a99aee6a42
commit
639ef19fbc
@ -15,7 +15,7 @@ use crate::{
|
|||||||
error::{Error, FinalError},
|
error::{Error, FinalError},
|
||||||
list::FileInArchive,
|
list::FileInArchive,
|
||||||
utils::{
|
utils::{
|
||||||
self, cd_into_same_dir_as,
|
cd_into_same_dir_as,
|
||||||
logger::{info, warning},
|
logger::{info, warning},
|
||||||
Bytes, EscapedPathDisplay, FileVisibilityPolicy,
|
Bytes, EscapedPathDisplay, FileVisibilityPolicy,
|
||||||
},
|
},
|
||||||
@ -68,9 +68,8 @@ where
|
|||||||
let metadata = match path.metadata() {
|
let metadata = match path.metadata() {
|
||||||
Ok(metadata) => metadata,
|
Ok(metadata) => metadata,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) {
|
if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() {
|
||||||
// This path is for a broken symlink
|
// This path is for a broken symlink, ignore it
|
||||||
// We just ignore it
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
|
@ -131,9 +131,8 @@ where
|
|||||||
let mut file = match fs::File::open(path) {
|
let mut file = match fs::File::open(path) {
|
||||||
Ok(f) => f,
|
Ok(f) => f,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) {
|
if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() {
|
||||||
// This path is for a broken symlink
|
// This path is for a broken symlink, ignore it
|
||||||
// We just ignore it
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
|
@ -20,7 +20,7 @@ use crate::{
|
|||||||
error::FinalError,
|
error::FinalError,
|
||||||
list::FileInArchive,
|
list::FileInArchive,
|
||||||
utils::{
|
utils::{
|
||||||
self, cd_into_same_dir_as, get_invalid_utf8_paths,
|
cd_into_same_dir_as, get_invalid_utf8_paths,
|
||||||
logger::{info, info_accessible, warning},
|
logger::{info, info_accessible, warning},
|
||||||
pretty_format_list_of_paths, strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
|
pretty_format_list_of_paths, strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy,
|
||||||
},
|
},
|
||||||
@ -214,9 +214,8 @@ where
|
|||||||
let metadata = match path.metadata() {
|
let metadata = match path.metadata() {
|
||||||
Ok(metadata) => metadata,
|
Ok(metadata) => metadata,
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) {
|
if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() {
|
||||||
// This path is for a broken symlink
|
// This path is for a broken symlink, ignore it
|
||||||
// We just ignore it
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
return Err(e.into());
|
return Err(e.into());
|
||||||
|
@ -146,13 +146,3 @@ pub fn try_infer_extension(path: &Path) -> Option<Extension> {
|
|||||||
None
|
None
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
/// Returns true if a path is a symlink.
|
|
||||||
///
|
|
||||||
/// This is the same as the nightly <https://doc.rust-lang.org/std/path/struct.Path.html#method.is_symlink>
|
|
||||||
/// Useful to detect broken symlinks when compressing. (So we can safely ignore them)
|
|
||||||
pub fn is_symlink(path: &Path) -> bool {
|
|
||||||
fs::symlink_metadata(path)
|
|
||||||
.map(|m| m.file_type().is_symlink())
|
|
||||||
.unwrap_or(false)
|
|
||||||
}
|
|
||||||
|
@ -18,7 +18,7 @@ pub use self::{
|
|||||||
EscapedPathDisplay,
|
EscapedPathDisplay,
|
||||||
},
|
},
|
||||||
fs::{
|
fs::{
|
||||||
cd_into_same_dir_as, clear_path, create_dir_if_non_existent, is_path_stdin, is_symlink, remove_file_or_dir,
|
cd_into_same_dir_as, clear_path, create_dir_if_non_existent, is_path_stdin, remove_file_or_dir,
|
||||||
try_infer_extension,
|
try_infer_extension,
|
||||||
},
|
},
|
||||||
question::{ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy},
|
question::{ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy},
|
||||||
|
Loading…
x
Reference in New Issue
Block a user