mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
ln: don't return an empty path in relative_path
This commit is contained in:
parent
439b7e0ca5
commit
3d3af5c8ca
2 changed files with 12 additions and 1 deletions
|
@ -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 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()
|
.components()
|
||||||
.skip(suffix_pos + 1)
|
.skip(suffix_pos + 1)
|
||||||
.map(|_| OsStr::new(".."))
|
.map(|_| OsStr::new(".."))
|
||||||
.chain(src_iter)
|
.chain(src_iter)
|
||||||
.collect();
|
.collect();
|
||||||
|
if result.as_os_str().is_empty() {
|
||||||
|
result.push(".");
|
||||||
|
}
|
||||||
Ok(result.into())
|
Ok(result.into())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -580,3 +580,11 @@ fn test_relative_src_already_symlink() {
|
||||||
ucmd.arg("-sr").arg("file2").arg("file3").succeeds();
|
ucmd.arg("-sr").arg("file2").arg("file3").succeeds();
|
||||||
assert!(at.resolve_link("file3").ends_with("file1"));
|
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…
Add table
Add a link
Reference in a new issue