Commit graph

8191 commits

Author SHA1 Message Date
Daniel Hofstetter
07b218e55a Replace possible_values() with value_parser() 2022-08-04 14:38:10 +02:00
Pierre Marsais
e1991525af
cp: Implement --sparse flag (#3766)
* cp: Refactor `reflink`/`sparse` handling to enable `--sparse` flag

`--sparse` and `--reflink` options have a lot of similarities:
 - They have similar options (`always`, `never`, `auto`)
 - Both need OS specific handling
 - They can be mutually exclusive

Prior to this change, `sparse` was defined as `CopyMode`, but `reflink`
wasn't. Given the similarities, it makes sense to handle them similarly.

The idea behind this change is to move all OS specific file copy
handling in the `copy_on_write_*` functions. Those function then
dispatch to the correct logic depending on the arguments (at the moment,
the tuple `(reflink, sparse)`).

Also, move the handling of `--reflink=never` from `copy_file` to the
`copy_on_write_*` functions, at the cost of a bit of code duplication,
to allow `copy_on_write_*` to handle all cases (and later handle
`--reflink=never` with `--sparse`).

* cp: Implement `--sparse` flag

This begins to address #3362

At the moment, only the `--sparse=always` logic matches the requirement
form GNU cp info page, i.e. always make holes in destination when
possible.

Sparse copy is done by copying the source to the destination block by
block (blocks being of the destination's fs block size). If the block
only holds NUL bytes, we don't write to the destination.

About `--sparse=auto`: according to GNU cp info page, the destination
file will be made sparse if the source file is sparse as well. The next
step are likely to use `lseek` with `SEEK_HOLE` detect if the source
file has holes. Currently, this has the same behaviour as
`--sparse=never`. This `SEEK_HOLE` logic can also be applied to
`--sparse=always` to improve performance when copying sparse files.

About `--sparse=never`: from my understanding, it is not guaranteed that
Rust's `fs::copy` will always produce a file with no holes, as
["platform-specific behavior may change in the
future"](https://doc.rust-lang.org/std/fs/fn.copy.html#platform-specific-behavior)

About other platforms:
 - `macos`: The solution may be to use `fcntl` command `F_PUNCHHOLE`.
 - `windows`: I only see `FSCTL_SET_SPARSE`.

This should pass the following GNU tests:
 - `tests/cp/sparse.sh`
 - `tests/cp/sparse-2.sh`
 - `tests/cp/sparse-extents.sh`
 - `tests/cp/sparse-extents-2.sh`

`sparse-perf.sh` needs `--sparse=auto`, and in particular a way to skip
holes in the source file.

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2022-08-04 13:22:59 +02:00
Pierre Marsais
90a9829287
cp: truncate destination when --reflink is set (#3759)
* cp: truncate destination when `--reflink` is set

This is needed in order to allow overriding an existing file.

```
$ truncate -s 512M /tmp/disk.img
$ mkfs.btrfs /tmp/disk.img
[...]
$ mkdir /tmp/disk
$ sudo mount /tmp/disk.img /tmp/disk
$ sudo chown $(id -u):$(id -g) -R /tmp/disk
$ for i in $(seq 0 8192); do echo -ne 'a' >>/tmp/disk/src1; done
$ echo "success" >/tmp/disk/src2
$
$ # GNU ls supports overriding files created with `--reflink`
$ cp --reflink=always /tmp/disk/src1 /tmp/disk/dst1
$ cp --reflink=always /tmp/disk/src2 /tmp/disk/dst1
$ cat /tmp/disk/dst1
success
$
$ # Now testing with uutils
$ cargo run cp --reflink=always /tmp/disk/src1 /tmp/disk/dst2
    Finished dev [unoptimized + debuginfo] target(s) in 0.25s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src1 /tmp/disk/dst2`
$ cargo run cp --reflink=always /tmp/disk/src2 /tmp/disk/dst2
    Finished dev [unoptimized + debuginfo] target(s) in 0.26s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src2 /tmp/disk/dst2`
cp: failed to clone "/tmp/disk/src2" from "/tmp/disk/dst2": Invalid argument (os error 22)
$ cat /tmp/disk/dst2
[lots of 'a']
$
$ # With truncate(true)
$ cargo run cp --reflink=always /tmp/disk/src1 /tmp/disk/dst3
    Finished dev [unoptimized + debuginfo] target(s) in 7.98s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src1 /tmp/disk/dst3`
$ cargo run cp --reflink=always /tmp/disk/src2 /tmp/disk/dst3
    Finished dev [unoptimized + debuginfo] target(s) in 0.27s
     Running `target/debug/coreutils cp --reflink=always /tmp/disk/src2 /tmp/disk/dst3`
$ cat /tmp/disk/dst3
success
```
2022-08-04 08:50:19 +02:00
Sylvestre Ledru
aed0a5ce0f
Merge pull request #3737 from niyaznigmatullin/try_fix_F-headers
gnu-tests/F-headers: increase number of attempts
2022-08-02 22:22:44 +02:00
Sylvestre Ledru
59aede5f6c
Merge pull request #3768 from cakebaker/clap_replace_is_present
Replace deprecated is_present() with contains_id()
2022-08-02 22:21:10 +02:00
Daniel Hofstetter
7c3116330e Replace deprecated is_present() with contains_id() 2022-08-02 15:21:39 +02:00
Niyaz Nigmatullin
85021041b4 F-headers: try make 409 seconds timeout 2022-08-02 15:38:25 +03:00
Niyaz Nigmatullin
20a103f9c7 gnu-tests/F-headers: increase number of attempts 2022-08-02 15:38:25 +03:00
Sylvestre Ledru
c660fc700f
Merge pull request #3757 from cakebaker/clap_update
bump clap from 3.1.18 to 3.2.15
2022-08-02 09:56:01 +02:00
Sylvestre Ledru
dba21d5ee0
Merge pull request #3763 from uutils/dependabot/cargo/sha3-0.10.2
build(deps): bump sha3 from 0.10.1 to 0.10.2
2022-08-02 09:54:39 +02:00
Sylvestre Ledru
9b81e09f7a
Merge pull request #3764 from cakebaker/numfmt_preserve_trailing_zeros
numfmt: preserve trailing zeros
2022-08-01 13:32:55 +02:00
Sylvestre Ledru
7af3327c5c doc: refresh of the targets 2022-08-01 10:26:31 +02:00
Sylvestre Ledru
025cb75416 doc: fix some flake8 warnings 2022-08-01 10:24:50 +02:00
Sylvestre Ledru
0d593f334b compiles_table: reformat with black 2022-08-01 10:24:50 +02:00
Sylvestre Ledru
d7a67454f6 docs: add missing commands 2022-08-01 10:24:50 +02:00
Sylvestre Ledru
2d4c0cc227
doc: mark the deprecation comment as bold 2022-08-01 10:23:37 +02:00
Sylvestre Ledru
7f51d64a34 doc: comment that the table isn't up to date 2022-08-01 10:06:19 +02:00
Sylvestre Ledru
86a32049b3 doc: move the list of target into a different file 2022-08-01 10:06:15 +02:00
Daniel Hofstetter
e642ca90dd numfmt: preserve trailing zeros 2022-08-01 09:48:13 +02:00
dependabot[bot]
92778de1f4
build(deps): bump sha3 from 0.10.1 to 0.10.2
Bumps [sha3](https://github.com/RustCrypto/hashes) from 0.10.1 to 0.10.2.
- [Release notes](https://github.com/RustCrypto/hashes/releases)
- [Commits](https://github.com/RustCrypto/hashes/compare/sha3-v0.10.1...sha3-v0.10.2)

---
updated-dependencies:
- dependency-name: sha3
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-01 06:39:05 +00:00
Pierre Marsais
4ad0d5c5a3
ls: Implement --zero flag. (#2929) (#3746)
* ls: Implement --zero flag. (#2929)

This flag can be used to provide a easy machine parseable output from
ls, as discussed in the GNU bug report
https://debbugs.gnu.org/cgi/bugreport.cgi?bug=49716.

There are some peculiarities with this flag:

 - Current implementation of GNU ls of the `--zero` flag implies some
   other flags. Those can be overridden by setting those flags after
   `--zero` in the command line.
 - This flag is not compatible with `--dired`. This patch is not 100%
   compliant with GNU ls: GNU ls `--zero` will fail if `--dired` and
   `-l` are set, while with this patch only `--dired` is needed for the
   command to fail.

We also add `--dired` flag to the parser, with no additional behaviour
change.

Testing done:
```
$ bash util/build-gnu.sh
 [...]
$ bash util/run-gnu-test.sh tests/ls/zero-option.sh
 [...]
 PASS: tests/ls/zero-option.sh
 ============================================================================
 Testsuite summary for GNU coreutils 9.1.36-8ec11
 ============================================================================
 # TOTAL: 1
 # PASS:  1
 # SKIP:  0
 # XFAIL: 0
 # FAIL:  0
 # XPASS: 0
 # ERROR: 0
 ============================================================================
```

* Use the US way to spell Behavior

* Fix formatting with cargo fmt -- tests/by-util/test_ls.rs

* Simplify --zero flag overriding logic by using index_of

Also, allow multiple --zero flags, as this is possible with GNU ls
command. Only the last one is taken into account.

Co-authored-by: Sylvestre Ledru <sledru@mozilla.com>
2022-07-31 19:02:50 +02:00
Sylvestre Ledru
38679f1c1b
Merge pull request #3751 from cakebaker/numfmt_format
numfmt: implement --format
2022-07-29 18:40:18 +02:00
Sylvestre Ledru
612f874d8f
Merge pull request #3755 from uutils/dependabot/github_actions/vmactions/freebsd-vm-0.2.3
build(deps): bump vmactions/freebsd-vm from 0.2.1 to 0.2.3
2022-07-29 18:40:02 +02:00
Daniel Hofstetter
fc4544c42b bump clap from 3.1.18 to 3.2.15 2022-07-29 14:05:02 +02:00
dependabot[bot]
e7cde6a3b9
build(deps): bump vmactions/freebsd-vm from 0.2.1 to 0.2.3
Bumps [vmactions/freebsd-vm](https://github.com/vmactions/freebsd-vm) from 0.2.1 to 0.2.3.
- [Release notes](https://github.com/vmactions/freebsd-vm/releases)
- [Commits](https://github.com/vmactions/freebsd-vm/compare/v0.2.1...v0.2.3)

---
updated-dependencies:
- dependency-name: vmactions/freebsd-vm
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-29 06:33:48 +00:00
Sylvestre Ledru
35f6e2a53a
Merge pull request #3749 from uutils/dependabot/cargo/lscolors-0.11.0
build(deps): bump lscolors from 0.10.0 to 0.11.0
2022-07-28 21:56:41 +02:00
Sylvestre Ledru
fd295d65b7
Merge pull request #3750 from uutils/dependabot/github_actions/vmactions/freebsd-vm-0.2.1
build(deps): bump vmactions/freebsd-vm from 0.2.0 to 0.2.1
2022-07-28 14:38:31 +02:00
Owen Anderson
8bdee49cdd
Speed up sum by using reasonable read buffer sizes. (#3741)
* Speed up sum by using reasonable read buffer sizes.

Use a 4K read buffer for each of the checksum functions, which seems
reasonable. This improves the performance of BSD checksums on
odyssey1024.txt from 399ms to 325ms on my laptop, and of SysV
checksums from 242ms to 67ms.

* Add BENCHMARKING.md for `sum`.

* Add comment regarding block sizes.

* Improve portability of BENCHMARKING.md

* Make `div_ceil` const and enhance comment.
2022-07-28 14:38:09 +02:00
Daniel Hofstetter
ee13bc41e7 numfmt: implement --format 2022-07-28 09:59:30 +02:00
dependabot[bot]
c49aa606f4
build(deps): bump vmactions/freebsd-vm from 0.2.0 to 0.2.1
Bumps [vmactions/freebsd-vm](https://github.com/vmactions/freebsd-vm) from 0.2.0 to 0.2.1.
- [Release notes](https://github.com/vmactions/freebsd-vm/releases)
- [Commits](https://github.com/vmactions/freebsd-vm/compare/v0.2.0...v0.2.1)

---
updated-dependencies:
- dependency-name: vmactions/freebsd-vm
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-28 06:58:02 +00:00
dependabot[bot]
0a8d0eaf6e
build(deps): bump lscolors from 0.10.0 to 0.11.0
Bumps [lscolors](https://github.com/sharkdp/lscolors) from 0.10.0 to 0.11.0.
- [Release notes](https://github.com/sharkdp/lscolors/releases)
- [Commits](https://github.com/sharkdp/lscolors/compare/v0.10.0...v0.11.0)

---
updated-dependencies:
- dependency-name: lscolors
  dependency-type: direct:production
  update-type: version-update:semver-minor
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-28 06:51:09 +00:00
Sam Nystrom
4e72e284b5
ls: silently ignore -T option (#3718)
* ls: silently ignore `-T` option
2022-07-26 10:35:43 +02:00
Sylvestre Ledru
eeb4cdab58
Merge pull request #3743 from niyaznigmatullin/basenc_gnu_tests
basenc: error code on wrong usage, usage test
2022-07-25 23:20:25 +02:00
Niyaz Nigmatullin
e5fc8bca8d basenc: fix error code on on wrong arguments, fix usage printing test 2022-07-25 23:12:10 +03:00
Sylvestre Ledru
9f9fb1901f
Merge pull request #3745 from uutils/dependabot/cargo/redox_syscall-0.2.15
build(deps): bump redox_syscall from 0.2.13 to 0.2.15
2022-07-25 21:15:30 +02:00
Sylvestre Ledru
2fa4d6a2bb
Merge pull request #3740 from resistor/main
Implement wc fast paths that skip Unicode decoding.
2022-07-25 21:15:13 +02:00
dependabot[bot]
fa87200f5e
build(deps): bump redox_syscall from 0.2.13 to 0.2.15
Bumps redox_syscall from 0.2.13 to 0.2.15.

---
updated-dependencies:
- dependency-name: redox_syscall
  dependency-type: direct:production
  update-type: version-update:semver-patch
...

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-25 06:38:03 +00:00
Owen Anderson
0e7f1c4c0d Add missing testcases for wc. 2022-07-24 21:56:07 -07:00
Sylvestre Ledru
41003f4478
Merge pull request #3742 from cakebaker/numfmt_float
numfmt: don't round floats if --from is "none"
2022-07-24 20:24:53 +02:00
Daniel Hofstetter
34b4853890 numfmt: don't round floats if --from is "none" 2022-07-24 16:25:52 +02:00
Sylvestre Ledru
62305e67d1
Merge pull request #3719 from andrewbaptist/main
split: Don't overwrite files
2022-07-23 22:54:57 +02:00
Owen Anderson
d5f59f23fa Implement wc fast paths that skip Unicode decoding.
Byte, character, and line counting can all be done on the raw bytes
of the incoming stream without decoding the Unicode characters. This
fact was previously exploited in specific fast paths for counting
characters and counting lines. This change unifies those fast paths into
a single shared fast paths, using const generics to specialize the
function for each use case. This has the benefit of making sure that all
combinations of these Unicode-oblivious fast paths benefit from the same
optimization.

On my laptop, this speeds up `wc -clm odyssey1024.txt` from 840ms to
120ms. I experimented with using a filter loop for line counting, but
continuing to use the bytecount crate came out ahead by a significant
margin.
2022-07-23 10:45:26 -07:00
Sylvestre Ledru
ec9130a4d7
Merge pull request #3735 from resistor/main
Implement a fast path for character counting in wc.
2022-07-22 13:29:47 +02:00
Sylvestre Ledru
f82ada645e
Merge pull request #3731 from sylvestre/fs-doc
document some common fs functions
2022-07-22 13:29:15 +02:00
Niyaz Nigmatullin
5f3f1112d1
Basename arguments simple format (#3736)
* basename: support simple format

* tests/basename: add tests for simple format

* basename: follow clippy advice
2022-07-22 13:28:54 +02:00
Sylvestre Ledru
9a1b4b537a
Merge pull request #3739 from jeckersb/nice-unsafe-nit
nice: Move call to Errno::clear() outside of unsafe block
2022-07-22 13:27:28 +02:00
John Eckersberg
282b368b28 nice: Move call to Errno::clear() outside of unsafe block
Minor nitpick (of my own previous patch!), Errno::clear() is a safe
function, it should not be inside of the unsafe block.
2022-07-21 15:57:21 -04:00
Andrew Baptist
f2cfc15a70 split: Don't overwrite files
Check that a file exists by calling create_new and changing the
interface of instantiate_current_writer to return a Result rather
than calling unwrap.
2022-07-21 12:06:13 -04:00
Sylvestre Ledru
be0cc8ff67
Merge pull request #3738 from cakebaker/numfmt_enable_test
numfmt: enable ignored test
2022-07-21 14:52:04 +02:00
Daniel Hofstetter
29c4d08ee9 numfmt: enable ignored test 2022-07-21 13:20:42 +02:00