From 639ef19fbc5800256c3bfd46db4db2cfcd2dfed7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Marcos=20P=2E=20Bezerra?= Date: Sun, 17 Nov 2024 21:05:58 -0300 Subject: [PATCH] chore: simplify code after feature stabilization no need to reimplement `Path::is_symlink` anymore --- src/archive/sevenz.rs | 7 +++---- src/archive/tar.rs | 5 ++--- src/archive/zip.rs | 7 +++---- src/utils/fs.rs | 10 ---------- src/utils/mod.rs | 2 +- 5 files changed, 9 insertions(+), 22 deletions(-) diff --git a/src/archive/sevenz.rs b/src/archive/sevenz.rs index 04da19c3..af5ca830 100644 --- a/src/archive/sevenz.rs +++ b/src/archive/sevenz.rs @@ -15,7 +15,7 @@ use crate::{ error::{Error, FinalError}, list::FileInArchive, utils::{ - self, cd_into_same_dir_as, + cd_into_same_dir_as, logger::{info, warning}, Bytes, EscapedPathDisplay, FileVisibilityPolicy, }, @@ -68,9 +68,8 @@ where let metadata = match path.metadata() { Ok(metadata) => metadata, Err(e) => { - if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) { - // This path is for a broken symlink - // We just ignore it + if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() { + // This path is for a broken symlink, ignore it continue; } return Err(e.into()); diff --git a/src/archive/tar.rs b/src/archive/tar.rs index 57c37370..6da1fc0c 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -131,9 +131,8 @@ where let mut file = match fs::File::open(path) { Ok(f) => f, Err(e) => { - if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) { - // This path is for a broken symlink - // We just ignore it + if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() { + // This path is for a broken symlink, ignore it continue; } return Err(e.into()); diff --git a/src/archive/zip.rs b/src/archive/zip.rs index 39b640e3..13018bd2 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -20,7 +20,7 @@ use crate::{ error::FinalError, list::FileInArchive, 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}, pretty_format_list_of_paths, strip_cur_dir, Bytes, EscapedPathDisplay, FileVisibilityPolicy, }, @@ -214,9 +214,8 @@ where let metadata = match path.metadata() { Ok(metadata) => metadata, Err(e) => { - if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) { - // This path is for a broken symlink - // We just ignore it + if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() { + // This path is for a broken symlink, ignore it continue; } return Err(e.into()); diff --git a/src/utils/fs.rs b/src/utils/fs.rs index a0928f28..c5f8c1dd 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -146,13 +146,3 @@ pub fn try_infer_extension(path: &Path) -> Option { None } } - -/// Returns true if a path is a symlink. -/// -/// This is the same as the nightly -/// 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) -} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index e2b51779..c1536897 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -18,7 +18,7 @@ pub use self::{ EscapedPathDisplay, }, 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, }, question::{ask_to_create_file, user_wants_to_continue, user_wants_to_overwrite, QuestionAction, QuestionPolicy},