Commit graph

4802 commits

Author SHA1 Message Date
Terts Diepraam
5621502a95 all: remove accept_{any, complete, lossy} and ConversionResult
Outside of tests, only `accept_any` was used, meaning that this unnecessarily complicated the code. The behaviour of `accept_any` is now the default (and only) option.
2022-08-17 14:57:28 +02:00
Terts Diepraam
0ed8b97a3f uucore: remove panic encoding handling
We never want utilities to panic on invalid input and it is not currently in use, so it can be removed safely.
2022-08-17 14:29:53 +02:00
Owen Anderson
9fad6fde35
Fix a bug in split where chunking would be skipped when the chunk size (#3800)
* Fix a bug in split where chunking would be skipped when the chunk size
happened to be an exact divisor of the buffer size used to read the
input stream.

The issue here was that file was being split byte-wise in chunks of 1G.
The input stream was being read in chunks of 8KB, which evenly divides
the chunk size. Because the check to allocate the next output chunk was
done at the bottom of the loop previously, it would never occur because
the current input chunk was fully consumed at that point. By moving the
check to the top of the loop (but still late enough that we know we have
bytes to write) we resolve this issue.

This scenario is unfortunately hard to write a test for, since we don't
explicitly control the input chunk size.

Fixes https://github.com/uutils/coreutils/issues/3790
2022-08-16 11:02:52 +02:00
Terts Diepraam
5ecabb8467
Merge pull request #3784 from jarkonik/main
Use `clap::ArgAction` in `true` and `false`
2022-08-16 10:50:32 +02:00
Niyaz Nigmatullin
0db17196ca readlink: follow clippy advice, add semicolon 2022-08-16 08:30:47 +03:00
Niyaz Nigmatullin
9c97b700ec readlink: reformat using rustfmt 2022-08-16 08:25:02 +03:00
Niyaz Nigmatullin
391143fe5b readlink: fix -n and -z no delimiter at the end 2022-08-16 08:21:12 +03:00
Niyaz Nigmatullin
5af152be2c uucore/fs: add Not a directory cases handling, e.g. for trailing slashes 2022-08-15 22:47:03 +03:00
Jaroslaw Konik
710e2af5fd Check argc instead of settings exclusive flag 2022-08-15 19:50:30 +02:00
Jaroslaw Konik
025a0dfa9e Use clap::ArgAction in true and false 2022-08-15 19:48:02 +02:00
Niyaz Nigmatullin
0e96cfa14b tail: fix notify usage for new version 2022-08-15 18:11:46 +03:00
dependabot[bot]
ade3b7540c
build(deps): bump notify from 5.0.0-pre.15 to 5.0.0-pre.16
Bumps [notify](https://github.com/notify-rs/notify) from 5.0.0-pre.15 to 5.0.0-pre.16.
- [Release notes](https://github.com/notify-rs/notify/releases)
- [Changelog](https://github.com/notify-rs/notify/blob/main/CHANGELOG.md)
- [Commits](https://github.com/notify-rs/notify/compare/5.0.0-pre.15...notify-5.0.0-pre.16)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-15 11:42:17 +00:00
5225225
c7b988c825
uutils: Remove use of mem::uninitialized (#3808) 2022-08-15 10:10:50 +02:00
Przemysław Fuchs
e2bab1d515
mv: fix error when moving directory to itself (#3809) 2022-08-15 10:10:04 +02:00
Sylvestre Ledru
00f5d91886 sha1sum: fix the -c usage (Closes: #3815) 2022-08-14 23:32:46 +02:00
anastygnome
1596f802f5 Rework tail plateform module in light of #2873
Optimize tail plateform module using the libc::stdin fd constant.

Commenting out `is_bad_symlink` as #2873 will not be fixed for the time being.
2022-08-14 13:30:57 +02:00
Jan Scheer
5258dec9a8
tail: fix race condition (#3798)
* tail: fix race condition (fix #3765)

There exists a race condition (RC) that can occur if changes to a path
happen after the initial print loop in `uu_tail()`, but before the
path is added to the notify-Watcher thread in `follow()`.

To minimize the window where the RC can occur, this moves starting the
Watcher thread and adding paths to it from `follow()` to the initial
print loop in `uu_tail()`.

Additionally, to make sure the RC cannot happen in
"gnu/tests/tail-2/F-headers.sh", the error message that is used as a trigger
in this test, is delayed until the path is added to the Watcher thread.

* build-gnu: remove workarounds for tail

Remove workarounds for "tests/tail-2/F-headers.sh" which are
(presumably) no longer needed because of the race condition fix.

* build-gnu: remove workarounds for tail

Remove workarounds for "tests/tail-2/F-headers.sh" which are
(presumably) no longer needed because of the race condition fix.

* tail: refactor to minimize chances of RC

Move "adding paths to Watcher thread" to its own loop and run this loop
before the initial tail-print-loop in order to minimize the window for
race conditions.
2022-08-14 01:01:15 +02:00
David Carlier
b5bb070777 while at it, let's do OpenBSD. 2022-08-13 10:21:30 +01:00
David Carlier
36561c9526 uucore fix NetBSD build. 2022-08-13 08:24:45 +01:00
Daniel Hofstetter
fcb7185279 Disable "broken intra doc links" lint 2022-08-12 14:48:59 +02:00
Daniel Hofstetter
689000576b du: remove useless transmute to fix clippy warning 2022-08-12 10:56:13 +02:00
Daniel Hofstetter
898914b6fb touch: remove transmute to fix clippy warning 2022-08-12 10:54:59 +02:00
Daniel Hofstetter
bfa6e23166 numfmt: implement Eq to fix clippy warning 2022-08-12 07:49:05 +02:00
Daniel Hofstetter
c0c26c4c58 Replace deprecated values_of() with get_many() 2022-08-11 13:49:09 +02:00
Sylvestre Ledru
a2e0296ef2 remove some unnecessary parentheses 2022-08-10 22:58:27 +02:00
Sylvestre Ledru
9f1219005d fix the significant_drop_in_scrutinee clippy warning 2022-08-10 21:37:48 +02:00
Sylvestre Ledru
8692301ec7
Merge pull request #3754 from ackerleytng/main
Add `parse_glob` module and update `du` to use `parse_glob`
2022-08-10 19:28:40 +02:00
Sylvestre Ledru
e304758f61
Merge pull request #3801 from niyaznigmatullin/sort_wait_for_signal_handling
sort: wait when SIGINT was raised for the program to finish properly
2022-08-10 19:26:50 +02:00
Niyaz Nigmatullin
898be12a33 sort: add comments to wait_if_signal function and its usage 2022-08-10 15:31:03 +03:00
Niyaz Nigmatullin
e43872d4c7 sort: rename lock binding variable 2022-08-10 12:20:25 +03:00
Niyaz Nigmatullin
50f1e9a5fa sort: fix test_tmp_files_deleted_on_sigint, wait for signal handling at
the end of the program
2022-08-10 12:15:27 +03:00
Niyaz Nigmatullin
13e912bcbd touch: fix error handling 2022-08-10 11:07:22 +03:00
Ackerley Tng
c2bb9596d9 du: update du to use parse_glob::from_str 2022-08-09 10:36:23 +02:00
Ackerley Tng
898689d924 du: refactor pattern building in du 2022-08-09 10:36:23 +02:00
Ackerley Tng
defde8c91e uucore: add parse_glob module 2022-08-09 10:36:23 +02:00
dependabot[bot]
54840b5fe1
build(deps): bump ouroboros from 0.15.0 to 0.15.2
Bumps [ouroboros](https://github.com/joshua-maros/ouroboros) from 0.15.0 to 0.15.2.
- [Release notes](https://github.com/joshua-maros/ouroboros/releases)
- [Commits](https://github.com/joshua-maros/ouroboros/commits)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-08 06:30:58 +00:00
Koutheir Attouchi
81a762ced6 Use u64 instead of ino_t/dev_t types 2022-08-06 02:50:19 -04:00
Terts Diepraam
fa47af73d0
Merge pull request #3774 from sylvestre/consistency
Add more consistency in the --help output and declarations
2022-08-04 23:53:51 +02:00
Sylvestre Ledru
d957a11f34 Add more consistency in the --help output and declarations 2022-08-04 21:53:27 +02:00
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
Daniel Hofstetter
7c3116330e Replace deprecated is_present() with contains_id() 2022-08-02 15:21:39 +02: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
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