Special-case the root directory when linking to it

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.
This commit is contained in:
Benjamin Sago 2017-04-29 11:52:10 +01:00
parent f8b82642a6
commit 956aa85b3b
3 changed files with 7 additions and 3 deletions

View File

@ -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() {

View File

@ -1,4 +1,4 @@
broken -> /testcases/links/nowhere
forbidden -> /proc/1/root
root -> /
root -> /
usr -> /usr

View File

@ -3,5 +3,5 @@
│ └── <No such file or directory (os error 2)>
├── forbidden -> /proc/1/root
│ └── <Permission denied (os error 13)>
├── root -> /
├── root -> /
└── usr -> /usr