Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: simplify code after feature stabilization #740

Merged
merged 1 commit into from
Nov 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 3 additions & 4 deletions src/archive/sevenz.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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());
Expand Down
5 changes: 2 additions & 3 deletions src/archive/tar.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
7 changes: 3 additions & 4 deletions src/archive/zip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
},
Expand Down Expand Up @@ -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());
Expand Down
10 changes: 0 additions & 10 deletions src/utils/fs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -146,13 +146,3 @@ pub fn try_infer_extension(path: &Path) -> Option<Extension> {
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)
}
2 changes: 1 addition & 1 deletion src/utils/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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},
Expand Down