From 956aa85b3b6673a721ff0d3ac122c4111c7d3faa Mon Sep 17 00:00:00 2001 From: Benjamin Sago Date: Sat, 29 Apr 2017 11:52:10 +0100 Subject: [PATCH] Special-case the root directory when linking to it MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit It’s the only file where its path is the same as its file name, and has been the source of numerous bugs in the past… this special-case isn’t very clean, but it works. --- src/output/mod.rs | 6 +++++- xtests/links_1 | 2 +- xtests/links_T | 2 +- 3 files changed, 7 insertions(+), 3 deletions(-) diff --git a/src/output/mod.rs b/src/output/mod.rs index d776556..4cfe0b1 100644 --- a/src/output/mod.rs +++ b/src/output/mod.rs @@ -47,7 +47,11 @@ pub fn filename(file: &File, colours: &Colours, links: bool, classify: bool) -> bits.push(colours.punctuation.paint("->")); bits.push(Style::default().paint(" ")); - if let Some(parent) = target.path.parent() { + if target.path.as_os_str() == "/" { + // Do nothing when linking to the root directory. + // The entirety of the path is the file name! + } + else if let Some(parent) = target.path.parent() { let coconut = parent.components().count(); if coconut == 1 && parent.has_root() { diff --git a/xtests/links_1 b/xtests/links_1 index 25344e0..83edc1b 100644 --- a/xtests/links_1 +++ b/xtests/links_1 @@ -1,4 +1,4 @@ broken -> /testcases/links/nowhere forbidden -> /proc/1/root -root -> / +root -> / usr -> /usr diff --git a/xtests/links_T b/xtests/links_T index 63d062b..0d611ab 100644 --- a/xtests/links_T +++ b/xtests/links_T @@ -3,5 +3,5 @@ │ └──  ├── forbidden -> /proc/1/root │ └──  -├── root -> / +├── root -> / └── usr -> /usr