From 645be4a668fad2d08e1017cdd0e995b3f808dd37 Mon Sep 17 00:00:00 2001 From: zwPapEr Date: Sun, 5 Apr 2020 18:27:01 +0800 Subject: delete fs canonicalize for show broken softlink without error fix https://github.com/Peltoche/lsd/issues/72 --- src/core.rs | 6 ------ src/main.rs | 4 ++++ tests/integration.rs | 23 +++++++++++++++++++++++ 3 files changed, 27 insertions(+), 6 deletions(-) diff --git a/src/core.rs b/src/core.rs index 6a120b3..57f653d 100644 --- a/src/core.rs +++ b/src/core.rs @@ -4,7 +4,6 @@ use crate::flags::{Display, Flags, IconTheme, Layout, WhenFlag}; use crate::icon::{self, Icons}; use crate::meta::Meta; use crate::{print_error, print_output, sort}; -use std::fs; use std::path::PathBuf; #[cfg(not(target_os = "windows"))] @@ -83,11 +82,6 @@ impl Core { }; for path in paths { - if let Err(err) = fs::canonicalize(&path) { - print_error!("cannot access '{}': {}", path.display(), err); - continue; - } - let mut meta = match Meta::from_path(&path) { Ok(meta) => meta, Err(err) => { diff --git a/src/main.rs b/src/main.rs index 5251884..e1537ce 100644 --- a/src/main.rs +++ b/src/main.rs @@ -84,6 +84,10 @@ macro_rules! print_output { fn main() { let matches = app::build().get_matches_from(wild::args_os()); + // input translate glob FILE without single quote into real names + // for example: + // * to all files matched + // '*' remain as '*' let inputs = matches .values_of("FILE") .expect("failed to retrieve cli value") diff --git a/tests/integration.rs b/tests/integration.rs index 05dfa95..8d38fc7 100644 --- a/tests/integration.rs +++ b/tests/integration.rs @@ -6,6 +6,9 @@ use assert_fs::prelude::*; use predicates::prelude::*; use std::process::Command; +#[cfg(unix)] +use std::os::unix::fs; + #[test] fn test_runs_okay() { cmd().assert().success(); @@ -134,6 +137,26 @@ fn test_list_inode_with_long_ok() { cmd().arg("-i").arg("-l").arg(dir.path()).assert().success(); } +#[cfg(unix)] +#[test] +fn test_list_broken_link_ok() { + let dir = tempdir(); + let broken_link = dir.path().join("broken-softlink"); + let matched = "No such file or directory"; + fs::symlink("not-existed-file", &broken_link).unwrap(); + + cmd() + .arg(&broken_link) + .assert() + .stderr(predicate::str::contains(matched).not()); + + cmd() + .arg("-l") + .arg(broken_link) + .assert() + .stderr(predicate::str::contains(matched).not()); +} + fn cmd() -> Command { Command::cargo_bin(env!("CARGO_PKG_NAME")).unwrap() } -- cgit v1.2.3