mirror of
https://github.com/uutils/coreutils
synced 2024-10-07 08:29:17 +00:00
ln: don't return an empty path in relative_path
This commit is contained in:
parent
439b7e0ca5
commit
3d3af5c8ca
|
@ -382,12 +382,15 @@ fn relative_path<'a>(src: &Path, dst: &Path) -> Result<Cow<'a, Path>> {
|
|||
|
||||
let src_iter = src_abs.components().skip(suffix_pos).map(|x| x.as_os_str());
|
||||
|
||||
let result: PathBuf = dst_abs
|
||||
let mut result: PathBuf = dst_abs
|
||||
.components()
|
||||
.skip(suffix_pos + 1)
|
||||
.map(|_| OsStr::new(".."))
|
||||
.chain(src_iter)
|
||||
.collect();
|
||||
if result.as_os_str().is_empty() {
|
||||
result.push(".");
|
||||
}
|
||||
Ok(result.into())
|
||||
}
|
||||
|
||||
|
|
|
@ -580,3 +580,11 @@ fn test_relative_src_already_symlink() {
|
|||
ucmd.arg("-sr").arg("file2").arg("file3").succeeds();
|
||||
assert!(at.resolve_link("file3").ends_with("file1"));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_relative_recursive() {
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
at.mkdir("dir");
|
||||
ucmd.args(&["-sr", "dir", "dir/recursive"]).succeeds();
|
||||
assert_eq!(at.resolve_link("dir/recursive"), ".");
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue