Explorar el Código

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.
Benjamin Sago hace 8 años
padre
commit
956aa85b3b
Se han modificado 3 ficheros con 7 adiciones y 3 borrados
  1. 5 1
      src/output/mod.rs
  2. 1 1
      xtests/links_1
  3. 1 1
      xtests/links_T

+ 5 - 1
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() {

+ 1 - 1
xtests/links_1

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

+ 1 - 1
xtests/links_T

@@ -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