Skip to content

cp: report symlink copy failures in archive mode - #17012

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/cp-archive-symlink-directory-17001
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/cp-archive-symlink-directory-17001

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Report the failed symlink copy and exit with status 1. Preserve the existing directory and its backup, and continue copying the remaining entries.

Closes #17001.

@codspeed

codspeed Bot commented Nov 30, 2026 •

Copy link
Copy Markdown
Contributor

Merging this PR will not alter performance

1 warning

⚠️ 5 benchmarks are dominated by system calls

System calls cannot be simulated consistently and are left out of the measure. The reported value understates the real cost. Switch to the Walltime instrument to measure them.

Learn more about system calls

See affected benchmarks

✅ 11 untouched benchmarks
⏩ 478 skipped benchmarks1


Comparing limadog9:fix/cp-archive-symlink-directory-17001 (54ce907) with main (f88b235)

Open in CodSpeed

Footnotes

  1. 478 benchmarks were skipped, so the baseline results were used instead. If they were deleted from the codebase, click here and archive them to remove them from the performance reports. ↩

@limadog9
limadog9 force-pushed the fix/cp-archive-symlink-directory-17001 branch from e7c27f1 to c637b91 Compare November 30, 2026 12:46
Comment thread src/uu/cp/src/cp.rs Outdated
// skipped update still counts as a destination for hard-link preservation.
if dest_metadata.is_dir() && !options.dereference(source_in_command_line) && source.is_symlink()
{
if options.copy_mode == CopyMode::Update

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this update branch isn't tested, could you please add a -au / --update=older case?

Comment thread src/uu/cp/src/cp.rs
return Err(CpError::Skipped(false));
}
if options.backup != BackupMode::None {
if options.copy_mode == CopyMode::Link {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same for the --link --backup path, please add a test

Comment thread src/uu/cp/src/cp.rs Outdated
}

/// Decide whether an existing destination should be updated.
fn should_update(source_metadata: &Metadata, dest: &Path, options: &Options) -> CopyResult<bool> {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

moving the update logic out of handle_copy_mode is a refactor on its own, please split it into a separate pr

Comment thread tests/by-util/test_cp.rs Outdated
at.mkdir("srcdir");
at.touch("srcdir/real.txt");
symlink("real.txt", at.plus("srcdir/link.txt")).unwrap();
// An external target tests dereferencing without requiring hard-link support.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why change these existing tests? does -aL now fail when the hard link can't be created?

Comment thread tests/by-util/test_cp.rs

#[rstest]
#[case::archive("-a")]
#[case::with_backup("-ab")]

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please add a case with -L too, to make sure the deref path still succeeds

@sylvestre

Copy link
Copy Markdown
Contributor

thanks for the patch!
The -a / -ab fix looks right, but the new update and --link branches have no tests, and the should_update refactor should go in its own pr (details inline).

@limadog9
limadog9 force-pushed the fix/cp-archive-symlink-directory-17001 branch from c637b91 to 75fb3d0 Compare November 30, 2026 23:30
@sylvestre
sylvestre force-pushed the fix/cp-archive-symlink-directory-17001 branch from 75fb3d0 to 54ce907 Compare December 1, 2026 15:40
@limadog9
limadog9 force-pushed the fix/cp-archive-symlink-directory-17001 branch from 54ce907 to 60652b3 Compare December 1, 2026 17:22

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

cp -a exits 0 when an existing directory prevents it from copying a symlink

2 participants