提交 f8624ed3 编写于 作者: K Kevin Ballard 提交者: Kevin Ballard

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.
上级 0c69eeca
......@@ -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)
}
}
......
broken -> /testcases/links/nowhere
broken -> nowhere
forbidden -> /proc/1/root
root -> /
usr -> /usr
/testcases/links
├── broken -> /testcases/links/nowhere
├── broken -> nowhere
│ └── <No such file or directory (os error 2)>
├── forbidden -> /proc/1/root
│ └── <Permission denied (os error 13)>
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册