Skip to content

cp: replace distinct symlinks when creating hard links - #15433

Open
limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/cp-hardlink-indirect-symlink
Open

limadog9 wants to merge 1 commit into
uutils:mainfrom
limadog9:fix/cp-hardlink-indirect-symlink

Conversation

@limadog9

Copy link
Copy Markdown
Contributor

Compare symlinks themselves under -P, so cp -lP replaces a distinct destination link even when both links resolve to the same file. Use atomic replacement and leave existing hard links unchanged.

Closes #6531

@limadog9
limadog9 force-pushed the fix/cp-hardlink-indirect-symlink branch from 8ebb363 to 0d58d3e Compare October 17, 2026 14:53
Comment thread src/uu/cp/src/cp.rs Outdated
) -> CopyResult<PerformedAction> {
match options.copy_mode {
CopyMode::Link => {
let replace_symlink = !options.dereference(source_in_command_line)

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.

with --backup, dest has already been moved away, so we would print "removed" on top of the backup message, no?

Comment thread src/uu/cp/src/cp.rs Outdated
)
})?;
if replace_symlink && options.verbose {
use std::io::Write;

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.

could you please use println! like delete_path does? or share the helper, it is almost the same code

Comment thread src/uu/cp/src/cp.rs Outdated
source,
dest,
options.dereference(source_in_command_line)
|| !source_is_symlink

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 condition is hard to read, could you please put it in a named variable?

@limadog9
limadog9 force-pushed the fix/cp-hardlink-indirect-symlink branch from 0d58d3e to e0e154b Compare October 24, 2026 14:30
@sylvestre
sylvestre force-pushed the fix/cp-hardlink-indirect-symlink branch from e0e154b to 76a46c3 Compare October 25, 2026 09:28

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: when doing hardlink copy of symlink, should replace a technically-different symlink

2 participants