nushell / nushell/nushell

coreutils' `--reflink` behavior with `cp`

Open
#8,762 0 comments 5 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

category:enhancement
Dominant language
Rust
Stars
40.5k
Forks
2.3k
Avg merge
1d 19h
Merged PRs (30d)
85

Description

Related problem

On some filesystems that support Copy-on-Write (CoW), GNU coreutils' cp supports "instant" copy by default, but this can be optionally disabled by supplying --reflink=never to create an actual duplicate block.

Based on some simple testing, it seems like nu's cp does CoW copy when -p is not supplied, but does actual copy when -p is supplied. However, it doesn't seem like this is documented in the help or the docs.

Describe the solution you'd like

Make an option, cp --nocow, that allows users to manually specify the behavior of cp on CoW systems, similar to coreutils' one.

Describe alternatives you've considered

Alternative would be to just document the -p's behavior to not use CoW, but this is unideal:

  • -p option should only do what the option suggests it will do, which is showing the progress, with no side effects.
  • When a user is copying a large directory, they might want to observe the progress, but would want the operation to finish ASAP, utilizing CoW whenever possible.
Additional context and details

I have tested this on Btrfs, using following commands:

# create a random file
dd if=/dev/urandom of=~/Desktop/testfile bs=1M count=16384
# copy w/o `-p` option
cp testfile testfile_cow
# copy w/ `-p` option
cp -p testfile testfile_nocow
# observe the `Exclusive` column of output
btrfs filesystem du .

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with Nushell's cp command implementation and its help output, then read the cp documentation at nushell.sh/commands/docs/cp.html. Reproduce the Btrfs behavior from the issue and determine where copy mode is selected. Done means cp exposes a documented --nocow option with behavior that can be verified against the CoW and non-CoW examples.

Written by the indexing model from the issue text.

Assessment

Tech stack
rust
Domain
cli, operating-systems
Issue type
Feature
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.