Skip to content

Commit 4bc2392

Browse files
committed
ln: include destination in symbolic link failure message
1 parent e0fef2a commit 4bc2392

3 files changed

Lines changed: 23 additions & 1 deletion

File tree

src/uu/ln/locales/en-US.ftl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,5 +34,6 @@ ln-prompt-replace = replace {$file}?
3434
ln-cannot-backup = cannot backup {$file}
3535
ln-failed-to-access = failed to access {$file}
3636
ln-failed-to-create-hard-link = failed to create hard link {$source} => {$dest}
37+
ln-failed-to-create-symbolic-link = failed to create symbolic link {$dest}
3738
ln-failed-to-create-hard-link-dir = {$source}: hard link not allowed for directory
3839
ln-backup = backup: {$backup}

src/uu/ln/src/ln.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -452,7 +452,15 @@ fn link(src: &Path, dst: &Path, settings: &Settings) -> LnResult<()> {
452452
}
453453

454454
let res = if settings.symbolic {
455-
symlink(&source, dst).map_err(Into::into)
455+
symlink(&source, dst).map_err(|e| {
456+
LnError::IoContext(
457+
UIoError::from(e),
458+
translate!(
459+
"ln-failed-to-create-symbolic-link",
460+
"dest" => dst.quote()
461+
),
462+
)
463+
})
456464
} else {
457465
let p = if settings.logical && source.is_symlink() {
458466
fs::canonicalize(&source).map_err(|e| {

tests/by-util/test_ln.rs

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -582,6 +582,19 @@ fn test_symlink_missing_destination() {
582582
));
583583
}
584584

585+
#[test]
586+
fn test_symlink_error_includes_destination() {
587+
let (at, mut ucmd) = at_and_ucmd!();
588+
let file = "test_symlink_error_includes_destination";
589+
let link = "no_such_dir/test_symlink_error_includes_destination";
590+
591+
at.touch(file);
592+
593+
ucmd.args(&["-s", file, link]).fails().stderr_is(format!(
594+
"ln: failed to create symbolic link '{link}': No such file or directory\n"
595+
));
596+
}
597+
585598
#[test]
586599
fn test_symlink_relative() {
587600
let (at, mut ucmd) = at_and_ucmd!();

0 commit comments

Comments
 (0)