mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-22 12:05:11 +00:00
Don't prepend current path to symlink targets
It's confusing, and `ls` doesn't do this either. We're not prepending the current path to all of the directory entries, and the user is going to interpret the symlink target as relative to the directory containing the symlink.
This commit is contained in:
parent
0c69eeca07
commit
f8624ed308
@ -169,28 +169,32 @@ impl<'dir> File<'dir> {
|
|||||||
Err(e) => return FileTarget::Err(e),
|
Err(e) => return FileTarget::Err(e),
|
||||||
};
|
};
|
||||||
|
|
||||||
let target_path = match self.dir {
|
let (metadata, ext) = {
|
||||||
Some(dir) => dir.join(&*path),
|
let target_path_ = match self.dir {
|
||||||
None => path
|
Some(dir) if dir.path != Path::new(".") => Some(dir.join(&*path)),
|
||||||
|
_ => None
|
||||||
|
};
|
||||||
|
let target_path = target_path_.as_ref().unwrap_or(&path);
|
||||||
|
// Use plain `metadata` instead of `symlink_metadata` - we *want* to follow links.
|
||||||
|
(fs::metadata(&target_path), ext(&target_path))
|
||||||
};
|
};
|
||||||
|
|
||||||
let filename = match target_path.components().next_back() {
|
let filename = match path.components().next_back() {
|
||||||
Some(comp) => comp.as_os_str().to_string_lossy().to_string(),
|
Some(comp) => comp.as_os_str().to_string_lossy().to_string(),
|
||||||
None => String::new(),
|
None => String::new(),
|
||||||
};
|
};
|
||||||
|
|
||||||
// Use plain `metadata` instead of `symlink_metadata` - we *want* to follow links.
|
if let Ok(metadata) = metadata {
|
||||||
if let Ok(metadata) = fs::metadata(&target_path) {
|
|
||||||
FileTarget::Ok(File {
|
FileTarget::Ok(File {
|
||||||
path: target_path.to_path_buf(),
|
path: path,
|
||||||
dir: self.dir,
|
dir: self.dir,
|
||||||
metadata: metadata,
|
metadata: metadata,
|
||||||
ext: ext(&target_path),
|
ext: ext,
|
||||||
name: filename,
|
name: filename,
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
FileTarget::Broken(target_path)
|
FileTarget::Broken(path)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
[36mbroken[0m [31m->[0m [4;31m/testcases/links/nowhere[0m
|
[36mbroken[0m [31m->[0m [4;31mnowhere[0m
|
||||||
[36mforbidden[0m [31m->[0m [4;31m/proc/1/root[0m
|
[36mforbidden[0m [31m->[0m [4;31m/proc/1/root[0m
|
||||||
[36mroot[0m [38;5;244m->[0m [1;34m/[0m
|
[36mroot[0m [38;5;244m->[0m [1;34m/[0m
|
||||||
[36musr[0m [38;5;244m->[0m [36m/[1;34musr[0m
|
[36musr[0m [38;5;244m->[0m [36m/[1;34musr[0m
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
[36m/testcases/[1;34mlinks[0m
|
[36m/testcases/[1;34mlinks[0m
|
||||||
[38;5;244m├──[0m [36mbroken[0m [31m->[0m [4;31m/testcases/links/nowhere[0m
|
[38;5;244m├──[0m [36mbroken[0m [31m->[0m [4;31mnowhere[0m
|
||||||
[38;5;244m│ └──[0m [31m<No such file or directory (os error 2)>[0m
|
[38;5;244m│ └──[0m [31m<No such file or directory (os error 2)>[0m
|
||||||
[38;5;244m├──[0m [36mforbidden[0m [31m->[0m [4;31m/proc/1/root[0m
|
[38;5;244m├──[0m [36mforbidden[0m [31m->[0m [4;31m/proc/1/root[0m
|
||||||
[38;5;244m│ └──[0m [31m<Permission denied (os error 13)>[0m
|
[38;5;244m│ └──[0m [31m<Permission denied (os error 13)>[0m
|
||||||
|
Loading…
Reference in New Issue
Block a user