1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-09-16 19:56:17 +00:00

Merge branch 'main' into cp-lb

This commit is contained in:
Sylvestre Ledru 2022-03-04 20:39:23 +01:00 committed by GitHub
commit 8df4f0bb4d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 74 additions and 15 deletions

View file

@ -149,8 +149,8 @@ fn test_realpath_dangling() {
let (at, mut ucmd) = at_and_ucmd!();
at.symlink_file("nonexistent-file", "link");
ucmd.arg("link")
.succeeds()
.stdout_only(at.plus_as_string("nonexistent-file\n"));
.fails()
.stderr_contains("realpath: link: No such file or directory");
}
#[test]
@ -202,3 +202,34 @@ fn test_realpath_missing() {
.succeeds()
.stdout_only(expect);
}
#[test]
fn test_realpath_when_symlink_is_absolute_and_enoent() {
let (at, mut ucmd) = at_and_ucmd!();
at.mkdir("dir2");
at.touch("dir2/bar");
at.mkdir("dir1");
at.symlink_file("dir2/bar", "dir1/foo1");
at.symlink_file("/dir2/bar", "dir1/foo2");
at.relative_symlink_file("dir2/baz", at.plus("dir1/foo3").to_str().unwrap());
#[cfg(unix)]
ucmd.arg("dir1/foo1")
.arg("dir1/foo2")
.arg("dir1/foo3")
.run()
.stdout_contains("/dir2/bar\n")
.stdout_contains("/dir2/baz\n")
.stderr_is("realpath: dir1/foo2: No such file or directory");
#[cfg(windows)]
ucmd.arg("dir1/foo1")
.arg("dir1/foo2")
.arg("dir1/foo3")
.run()
.stdout_contains("\\dir2\\bar\n")
.stdout_contains("\\dir2\\baz\n")
.stderr_is("realpath: dir1/foo2: No such file or directory");
}

View file

@ -701,6 +701,11 @@ impl AtPath {
symlink_file(&self.plus(original), &self.plus(link)).unwrap();
}
pub fn relative_symlink_file(&self, original: &str, link: &str) {
log_info("symlink", &format!("{},{}", original, link));
symlink_file(original, link).unwrap();
}
pub fn symlink_dir(&self, original: &str, link: &str) {
log_info(
"symlink",