Commit graph

4809 commits

Author SHA1 Message Date
Terts Diepraam
791fb98dcc tty: move from libc to nix
This moves the unsafe from our responsibility to nix and makes
the code a bit cleaner.
2022-08-18 00:59:27 +02:00
Sylvestre Ledru
87e3899477
Merge pull request #3832 from tertsdiepraam/simplify-encoding-handling
Simplify invalid encoding handling
2022-08-17 18:59:59 +02:00
Terts Diepraam
ba713b6365 Simplify invalid encoding handling into two small methods of Args
The previous encoding handling was unnecessarily complex. This commit removes the enum that specifies the handling and instead has two separate methods to collect the strings either with lossy conversion or by ignoring invalidly encoded strings.
2022-08-17 15:20:20 +02:00
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
Niyaz Nigmatullin
dc12639995 Fix completion with a clap update 2022-08-17 13:13:27 +03:00
Niyaz Nigmatullin
9cd898b885 remove nix 0.24.2 dependency 2022-08-17 13:13:27 +03:00
Niyaz Nigmatullin
f4df7ea4a0 cargo +1.56.1 update 2022-08-17 13:13:27 +03:00
Przemysław Fuchs
3acbd1c048
dd: Error message of invalid args is matched with GNU (#3831) 2022-08-17 11:40:42 +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