提交 956aa85b 编写于 作者: B Benjamin Sago

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.
上级 f8b82642
......@@ -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() {
......
broken -> /testcases/links/nowhere
forbidden -> /proc/1/root
root -> /
root -> /
usr -> /usr
......@@ -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
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册