Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion src/uu/ln/locales/en-US.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,6 @@ ln-error-missing-destination = missing destination file operand after {$operand}
ln-error-extra-operand = extra operand {$operand}
Try '{$program} --help' for more information.
ln-error-could-not-update = Could not update {$target}: {$error}
ln-error-cannot-stat = cannot stat {$path}: No such file or directory
ln-error-will-not-overwrite = will not overwrite just-created {$target} with {$source}
ln-prompt-replace = replace {$file}?
ln-cannot-backup = cannot backup {$file}
Expand Down
1 change: 0 additions & 1 deletion src/uu/ln/locales/fr-FR.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ ln-error-missing-destination = opérande de fichier de destination manquant apr
ln-error-extra-operand = opérande supplémentaire {$operand}
Essayez « {$program} --help » pour plus d'informations.
ln-error-could-not-update = Impossible de mettre à jour {$target} : {$error}
ln-error-cannot-stat = impossible d'analyser {$path} : Aucun fichier ou répertoire de ce nom
ln-error-will-not-overwrite = ne remplacera pas le fichier {$target} qui vient d'être créé par {$source}
ln-prompt-replace = remplacer {$file} ?
ln-cannot-backup = impossible de sauvegarder {$file}
Expand Down
13 changes: 3 additions & 10 deletions src/uu/ln/src/ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -334,22 +334,15 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
}
}
target_dir.to_path_buf()
} else if let Some(name) = srcpath.as_os_str().to_str() {
match Path::new(name).file_name() {
} else {
match srcpath.file_name() {
Some(basename) => target_dir.join(basename),
// This can be None only for "." or "..". Trying
// to create a link with such name will fail with
// EEXIST, which agrees with the behavior of GNU
// coreutils.
None => target_dir.join(name),
None => target_dir.join(srcpath),
}
} else {
show_error!(
"{}",
translate!("ln-error-cannot-stat", "path" => srcpath.quote())
);
all_successful = false;
continue;
};

if linked_destinations.contains(&targetpath) {
Expand Down
45 changes: 45 additions & 0 deletions tests/by-util/test_ln.rs
Original file line number Diff line number Diff line change
Expand Up @@ -378,6 +378,51 @@ fn test_symlink_target_dir() {
assert_eq!(at.resolve_link(file_b_link), file_b);
}

#[test]
#[cfg(target_os = "linux")]
fn test_symlink_target_dir_non_utf8_source_name() {
use std::ffi::OsStr;
use std::fs;
use std::os::unix::ffi::OsStrExt;

let scene = TestScenario::new(util_name!());
let at = &scene.fixtures;
let target_dir = "test_symlink_target_dir_non_utf8";
let source_bytes = b"source_\xFF\xFE";
let source_name = OsStr::from_bytes(source_bytes);

at.mkdir(target_dir);
at.touch(source_name);

scene
.ucmd()
.args(&["-s", "-t", target_dir])
.arg(source_name)
.succeeds()
.no_stderr();

let target_dir_path = at.plus(target_dir);
let mut dir_entries = fs::read_dir(&target_dir_path)
.expect("reading target directory entries after creating symlink");
let created_entry = dir_entries
.next()
.expect("finding created entry in target directory")
.expect("reading created target-directory entry");
assert!(
dir_entries.next().is_none(),
"expected only one created entry in target directory"
);
assert_eq!(
created_entry.file_name().as_os_str().as_bytes(),
source_bytes
);

let created_link_path = target_dir_path.join(source_name);
let created_link_target = fs::read_link(&created_link_path)
.expect("reading created symlink target in target directory");
assert_eq!(created_link_target.as_os_str().as_bytes(), source_bytes);
}

#[test]
fn test_symlink_target_dir_from_dir() {
let (at, mut ucmd) = at_and_ucmd!();
Expand Down
Loading