mirror of
https://github.com/Llewellynvdm/exa.git
synced 2024-11-11 07:10:56 +00:00
Merge pull request #169 from kballard/symlink_leading_path
Don't prepend current path to symlink targets
This commit is contained in:
commit
91ad09e188
@ -169,28 +169,32 @@ impl<'dir> File<'dir> {
|
||||
Err(e) => return FileTarget::Err(e),
|
||||
};
|
||||
|
||||
let target_path = match self.dir {
|
||||
Some(dir) => dir.join(&*path),
|
||||
None => path
|
||||
let (metadata, ext) = {
|
||||
let target_path_ = match self.dir {
|
||||
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(),
|
||||
None => String::new(),
|
||||
};
|
||||
|
||||
// Use plain `metadata` instead of `symlink_metadata` - we *want* to follow links.
|
||||
if let Ok(metadata) = fs::metadata(&target_path) {
|
||||
if let Ok(metadata) = metadata {
|
||||
FileTarget::Ok(File {
|
||||
path: target_path.to_path_buf(),
|
||||
path: path,
|
||||
dir: self.dir,
|
||||
metadata: metadata,
|
||||
ext: ext(&target_path),
|
||||
ext: ext,
|
||||
name: filename,
|
||||
})
|
||||
}
|
||||
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
|
||||
[36mroot[0m [38;5;244m->[0m [1;34m/[0m
|
||||
[36musr[0m [38;5;244m->[0m [36m/[1;34musr[0m
|
||||
|
@ -1,5 +1,5 @@
|
||||
[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 [36mforbidden[0m [31m->[0m [4;31m/proc/1/root[0m
|
||||
[38;5;244m│ └──[0m [31m<Permission denied (os error 13)>[0m
|
||||
|
Loading…
Reference in New Issue
Block a user