diff --git a/src/archive/tar.rs b/src/archive/tar.rs index 4764caa..3145bed 100644 --- a/src/archive/tar.rs +++ b/src/archive/tar.rs @@ -93,7 +93,7 @@ where let mut file = match fs::File::open(path) { Ok(f) => f, Err(e) => { - if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() { + if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) { // This path is for a broken symlink // We just ignore it continue; diff --git a/src/archive/zip.rs b/src/archive/zip.rs index b07d483..30dee2e 100644 --- a/src/archive/zip.rs +++ b/src/archive/zip.rs @@ -15,8 +15,8 @@ use crate::{ info, list::FileInArchive, utils::{ - cd_into_same_dir_as, concatenate_os_str_list, dir_is_empty, get_invalid_utf8_paths, strip_cur_dir, to_utf, - Bytes, + self, cd_into_same_dir_as, concatenate_os_str_list, dir_is_empty, get_invalid_utf8_paths, strip_cur_dir, + to_utf, Bytes, }, }; @@ -145,7 +145,7 @@ where let file_bytes = match fs::read(entry.path()) { Ok(b) => b, Err(e) => { - if e.kind() == std::io::ErrorKind::NotFound && path.is_symlink() { + if e.kind() == std::io::ErrorKind::NotFound && utils::is_symlink(path) { // This path is for a broken symlink // We just ignore it continue; diff --git a/src/lib.rs b/src/lib.rs index 8b35881..e337061 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -5,8 +5,6 @@ // used as a binary. Since `clap` doesn't remove URL markup in it's help output, // we don't mark them as URLs. This suppresses the relevant rustdoc warning: #![allow(rustdoc::bare_urls)] -// Useful to detect broken symlinks when compressing. (So we can safely ignore them) -#![feature(is_symlink)] // Macros should be declared before pub mod macros; diff --git a/src/utils/fs.rs b/src/utils/fs.rs index 1dd38e0..f6e5420 100644 --- a/src/utils/fs.rs +++ b/src/utils/fs.rs @@ -119,3 +119,10 @@ pub fn try_infer_extension(path: &Path) -> Option { 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) +} diff --git a/src/utils/mod.rs b/src/utils/mod.rs index 4c09cd5..e79c5ec 100644 --- a/src/utils/mod.rs +++ b/src/utils/mod.rs @@ -9,7 +9,9 @@ mod fs; mod question; pub use formatting::{concatenate_os_str_list, nice_directory_display, strip_cur_dir, to_utf, Bytes}; -pub use fs::{cd_into_same_dir_as, clear_path, create_dir_if_non_existent, dir_is_empty, try_infer_extension}; +pub use fs::{ + cd_into_same_dir_as, clear_path, create_dir_if_non_existent, dir_is_empty, is_symlink, try_infer_extension, +}; pub use question::{ create_or_ask_overwrite, user_wants_to_continue_decompressing, user_wants_to_overwrite, QuestionPolicy, };