mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-29 03:57:44 +00:00
ln
: allow final destination directory when using -nf
(#5975)
Closes: #5974
This commit is contained in:
parent
39bfa40acf
commit
564dd47297
2 changed files with 97 additions and 36 deletions
|
@ -301,11 +301,12 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
|
||||||
|
|
||||||
let mut all_successful = true;
|
let mut all_successful = true;
|
||||||
for srcpath in files {
|
for srcpath in files {
|
||||||
let targetpath =
|
let targetpath = if settings.no_dereference
|
||||||
if settings.no_dereference && matches!(settings.overwrite, OverwriteMode::Force) {
|
&& matches!(settings.overwrite, OverwriteMode::Force)
|
||||||
|
&& target_dir.is_symlink()
|
||||||
|
{
|
||||||
// In that case, we don't want to do link resolution
|
// In that case, we don't want to do link resolution
|
||||||
// We need to clean the target
|
// We need to clean the target
|
||||||
if target_dir.is_symlink() {
|
|
||||||
if target_dir.is_file() {
|
if target_dir.is_file() {
|
||||||
if let Err(e) = fs::remove_file(target_dir) {
|
if let Err(e) = fs::remove_file(target_dir) {
|
||||||
show_error!("Could not update {}: {}", target_dir.quote(), e);
|
show_error!("Could not update {}: {}", target_dir.quote(), e);
|
||||||
|
@ -319,7 +320,6 @@ fn link_files_in_dir(files: &[PathBuf], target_dir: &Path, settings: &Settings)
|
||||||
show_error!("Could not update {}: {}", target_dir.quote(), e);
|
show_error!("Could not update {}: {}", target_dir.quote(), e);
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
|
||||||
target_dir.to_path_buf()
|
target_dir.to_path_buf()
|
||||||
} else {
|
} else {
|
||||||
match srcpath.as_os_str().to_str() {
|
match srcpath.as_os_str().to_str() {
|
||||||
|
|
|
@ -549,6 +549,67 @@ fn test_symlink_no_deref_dir() {
|
||||||
assert_eq!(at.resolve_link(link), dir1);
|
assert_eq!(at.resolve_link(link), dir1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn test_symlink_no_deref_file_in_destination_dir() {
|
||||||
|
let scene = TestScenario::new(util_name!());
|
||||||
|
let at = &scene.fixtures;
|
||||||
|
|
||||||
|
let file1 = "foo";
|
||||||
|
let file2 = "bar";
|
||||||
|
|
||||||
|
let dest = "baz";
|
||||||
|
|
||||||
|
let link1 = "baz/foo";
|
||||||
|
let link2 = "baz/bar";
|
||||||
|
|
||||||
|
at.touch(file1);
|
||||||
|
at.touch(file2);
|
||||||
|
at.mkdir(dest);
|
||||||
|
|
||||||
|
assert!(at.file_exists(file1));
|
||||||
|
assert!(at.file_exists(file2));
|
||||||
|
assert!(at.dir_exists(dest));
|
||||||
|
|
||||||
|
// -n and -f should work alone
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.args(&["-sn", file1, dest])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
assert!(at.is_symlink(link1));
|
||||||
|
assert_eq!(at.resolve_link(link1), file1);
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.args(&["-sf", file1, dest])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
assert!(at.is_symlink(link1));
|
||||||
|
assert_eq!(at.resolve_link(link1), file1);
|
||||||
|
|
||||||
|
// -n alone should fail if destination exists already (it should now)
|
||||||
|
scene.ucmd().args(&["-sn", file1, dest]).fails();
|
||||||
|
|
||||||
|
// -nf should also work
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.args(&["-snf", file1, dest])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
assert!(at.is_symlink(link1));
|
||||||
|
assert_eq!(at.resolve_link(link1), file1);
|
||||||
|
|
||||||
|
scene
|
||||||
|
.ucmd()
|
||||||
|
.args(&["-snf", file1, file2, dest])
|
||||||
|
.succeeds()
|
||||||
|
.no_stderr();
|
||||||
|
assert!(at.is_symlink(link1));
|
||||||
|
assert_eq!(at.resolve_link(link1), file1);
|
||||||
|
assert!(at.is_symlink(link2));
|
||||||
|
assert_eq!(at.resolve_link(link2), file2);
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn test_symlink_no_deref_file() {
|
fn test_symlink_no_deref_file() {
|
||||||
let scene = TestScenario::new(util_name!());
|
let scene = TestScenario::new(util_name!());
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue