Repository navigation
Add hardlink flag to cp - #14359
Closed
jasha-hrp wants to merge 3 commits into
Closed
Add hardlink flag to cp#14359jasha-hrp wants to merge 3 commits into
jasha-hrp wants to merge 3 commits into
Conversation
jasha-hrp
marked this pull request as draft
November 16, 2024 19:13
Contributor
|
Closes #14306. @NotTheDr01ds, these tests pass when I run them locally. This is confusing because I haven't made any changes to Awaiting workflow approval to see if the CI runs. |
Contributor
|
Guidance regarding which area of the codebase to modify / focus on would be appreciated. |
Contributor
|
Taken from the uutils cp docs: |
Contributor
|
Closed in favor of #14365 |
fdncred
pushed a commit
that referenced
this pull request
Nov 20, 2026
## Description Implements #14306: `cp` gains a `-l`/`--link` flag matching GNU `cp -l`, which creates hard links to regular files instead of copying them. Combined with `-r` it can hard-link a whole directory tree (`cp -lr source dest`), the use case in the issue. The flag just exposes `uu_cp`'s existing `CopyMode::Link`. - `-l` cannot be combined with `-u`: uu_cp ignores `UpdateMode` in `CopyMode::Link`, so the combination is rejected with `IncompatibleParameters` rather than silently misbehaving. - When linking, symlinks are followed and their targets are linked, matching uutils' `resolve_dereference` (`!recursive || is_link`). `-P`/`--no-dereference` links the links themselves, as noted in the flag's help text. Fresh take on #14359, which went stale. ## User-facing changes (Release notes) `cp` now supports `-l`/`--link` to create hard links to regular files instead of copying, e.g. `cp -l a.txt b.txt`, or `cp -lr dir_a dir_b` to recursively link a directory tree (symlinks inside the tree are followed unless `-P` is given). `-l` cannot be combined with `-u`. ## Additional notes - closes #14306 - supersedes #14359 - Tests in `crates/nu-command/tests/commands/ucp.rs` check hard-link semantics portably (write-through, no inode APIs): `cp -l` on a single file, `cp -lr` on a tree with a symlink, `cp -l` over an existing destination, `cp -lf` replacing it, and `cp -lu` erroring. - `linking_does_not_change_source_mode` is a regression test for uutils/coreutils#15087 (chmod after hard link used to mutate the source's mode); uu_cp 0.13.0 on main has the fix. - `commands::ucp::test_cp_debug_default` fails on macOS on unmodified `main` (uu_cp reports `reflink: yes` on APFS); unrelated to this change.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Add flag to
cpbuiltin to enable creating hardlinks.This make use of the
-l/--linksflag from coreutils' cp command.See https://uutils.github.io/coreutils/docs/utils/cp.html
User-Facing Changes
Should add extra flag to
cp.Default behavior of
cpshould not changeTests + Formatting
Added some unit tests
TODO:
cargo fmt --all -- --checkto check standard code formatting (cargo fmt --allapplies these changes)cargo clippy --workspace -- -D warnings -D clippy::unwrap_usedto check that you're using the standard code stylecargo test --workspaceto check that all tests pass (on Windows make sure to enable developer mode)cargo run -- -c "use toolkit.nu; toolkit test stdlib"to run the tests for the standard library-->
After Submitting