Skip to content

cp: reject --attributes-only self-copies (#13161) - #13894

Open
l46983284-cpu wants to merge 1 commit into
uutils:mainfrom
l46983284-cpu:fix-13161-cp-attronly-samefile
Open

cp: reject --attributes-only self-copies (#13161)#13894
l46983284-cpu wants to merge 1 commit into
uutils:mainfrom
l46983284-cpu:fix-13161-cp-attronly-samefile

Conversation

@l46983284-cpu

Copy link
Copy Markdown
Contributor

Fixes the first point of #13161.

The guard from #6051 skips handle_existing_dest for --attributes-only,
which also skipped the same-file check, so cp --attributes-only a a
silently succeeded (GNU rejects it with "'a' and 'a' are the same file").

Add an explicit check on the attributes-only path reusing
is_forbidden_to_copy_to_same_file, so the --force --backup allowance
keeps working exactly like the regular path.

Two tests cover a a and a ./a.

Note: the second point of the issue (chmod by path instead of fd, a
TOCTOU window on the normal attributes-only copy to a different file)
is intentionally left out of this PR as a follow-up.

The guard added in uutils#6051 skipped handle_existing_dest for
--attributes-only, losing the same-file check with it:
`cp --attributes-only a a` silently succeeded. GNU rejects this
with "'a' and 'a' are the same file". Add an explicit check on
the attributes-only path, reusing the existing predicate so the
--force --backup allowance keeps working.

Signed-off-by: Alex Chen <l46983284@gmail.com>
@codspeed-hq

codspeed-hq Bot commented Aug 12, 2026

Copy link
Copy Markdown

Merging this PR will degrade performance by 4.01%

⚠️ Different runtime environments detected

Some benchmarks with significant performance changes were compared across different runtime environments,
which may affect the accuracy of the results.

Open the report in CodSpeed to investigate

⚡ 2 improved benchmarks
❌ 1 regressed benchmark
✅ 344 untouched benchmarks
⏩ 46 skipped benchmarks1

Warning

Please fix the performance issues or acknowledge them on CodSpeed.

Performance Changes

Mode Benchmark BASE HEAD Efficiency
Simulation df_with_path 573.7 µs 704.8 µs -18.6%
Simulation du_max_depth_balanced_tree[(6, 4, 10)] 65.2 ms 62.4 ms +4.43%
Simulation du_summarize_balanced_tree[(5, 4, 10)] 16.8 ms 16.1 ms +4.05%

Tip

Investigate this regression by commenting @codspeedbot fix this regression on this PR, or directly use the CodSpeed MCP with your agent.


Comparing l46983284-cpu:fix-13161-cp-attronly-samefile (1c3accf) with main (822aa83)

Open in CodSpeed

Footnotes

  1. 46 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.

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.

1 participant