Commit graph

4933 commits

Author SHA1 Message Date
Terts Diepraam
e9e9a8166f uucore/ranges: refactor FromStr impl 2022-08-18 19:45:18 +02:00
dependabot[bot]
20809db439
build(deps): bump lscolors from 0.11.1 to 0.12.0
Bumps [lscolors](https://github.com/sharkdp/lscolors) from 0.11.1 to 0.12.0.
- [Release notes](https://github.com/sharkdp/lscolors/releases)
- [Commits](https://github.com/sharkdp/lscolors/compare/v0.11.1...v0.12.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-08-18 11:38:09 +00:00
Sylvestre Ledru
88261f36dd
Merge pull request #3834 from uutils/dependabot/cargo/once_cell-1.13.1
build(deps): bump once_cell from 1.13.0 to 1.13.1
2022-08-18 13:35:59 +02:00
Sylvestre Ledru
6f6784f113 Adjust the code after https://github.com/uutils/coreutils/pull/3832 2022-08-18 11:33:04 +02:00
Terts Diepraam
85e6f8659f stty: fix bsd/mac builds 2022-08-18 11:33:04 +02:00
Terts Diepraam
420c69aa98 stty: make compatible with Rust pre 1.61 2022-08-18 11:33:04 +02:00
Terts Diepraam
f861fc0854 stty: print special terminal information 2022-08-18 11:33:04 +02:00
Terts Diepraam
cc147a7c8d stty: expand --help information 2022-08-18 11:33:04 +02:00
Terts Diepraam
679fd2371e stty: disallow combining settings with --all and --save 2022-08-18 11:33:04 +02:00
Terts Diepraam
eac88022b2 stty: fix setting grouped flags 2022-08-18 11:33:04 +02:00
Terts Diepraam
96ea772016 stty: fix clippy warnings 2022-08-18 11:33:04 +02:00
Terts Diepraam
0c44fc07d2 stty: fix ixany and iutf8 not sane 2022-08-18 11:33:04 +02:00
Terts Diepraam
4cda8f33e7 stty: add grouped flags 2022-08-18 11:33:04 +02:00
Terts Diepraam
600cab0bd8 starting work on stty 2022-08-18 11:33:04 +02:00
Terts Diepraam
b983355bc4 uucore & cp: remove show_error_custom_description macros show_usage_error 2022-08-18 10:44:59 +02:00
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
Terts Diepraam
f255c0cae8 dir & vdir: fix docs not showing up on the website
uudoc was getting a dummy clap app to generate documentation from. Now the app from ls is returned instead, so that it actually shows something.
2022-08-17 22:33:32 +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
dependabot[bot]
e465d0520f
build(deps): bump once_cell from 1.13.0 to 1.13.1
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.13.0 to 1.13.1.
- [Release notes](https://github.com/matklad/once_cell/releases)
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.13.0...v1.13.1)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-08-17 16:20:25 +00: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
cdc664305e tail: reuse opened file with the same descriptor when
--follow=descriptor and renamed
2022-08-17 13:14:32 +03: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
Terts Diepraam
a3a69cf919 uucore: add filename as argument in help_usage and help_section
uucore: make help_section and help_usage take an argument to select a file
2022-08-16 19:22:41 +02:00
Terts Diepraam
c8e88e1898 add help_usage macro 2022-08-16 19:22:40 +02:00
Terts Diepraam
dedb969d75 add help file for base64 2022-08-16 19:20:37 +02:00
Terts Diepraam
2df00344f7 add help file for base32 2022-08-16 19:19:49 +02:00
Terts Diepraam
5a9380616b Use a markdown file named after the utils for help_section 2022-08-16 19:18:38 +02:00
Terts Diepraam
c4ba21f720 move numfmt help to a separate file 2022-08-16 19:18:36 +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
Daniel Hofstetter
fc4544c42b bump clap from 3.1.18 to 3.2.15 2022-07-29 14:05:02 +02: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
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]
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
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
2fa4d6a2bb
Merge pull request #3740 from resistor/main
Implement wc fast paths that skip Unicode decoding.
2022-07-25 21:15:13 +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
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
Owen Anderson
417ad0e384 Add rustdoc comment. 2022-07-20 23:32:50 -07:00
Owen Anderson
13762cae05 Implement a fast path for character counting in wc.
When wc is invoked with only the -m flag, we only need to count the
number of Unicode characters in the input. In order to do so, we don't
actually need to decode the input bytes into characters. Rather, we can
simply count the number of non-continuation bytes in the UTF-8 stream,
since every character will contain exactly one non-continuation byte.

On my laptop, this speeds up `wc -m odyssey1024.txt` from 745ms to
109ms.
2022-07-20 22:35:40 -07:00
Sylvestre Ledru
ba24565b60
Merge pull request #3732 from cakebaker/numfmt_auto_suf_si_i
numfmt: show "invalid suffix" error for "i" suffix
2022-07-20 22:51:14 +02:00
Sylvestre Ledru
ba44fd0e2b document some common fs functions 2022-07-20 17:51:53 +02:00
Daniel Hofstetter
74bd9a26d6 numfmt: show "invalid suffix" error for "i" suffix 2022-07-20 17:51:36 +02:00
Niyaz Nigmatullin
9f2a9fa6ff uucore/fs: make function more generic 2022-07-19 17:34:52 +03:00
Niyaz Nigmatullin
b76c53c090 ln: fix windows non-compiling code 2022-07-19 17:34:52 +03:00
Niyaz Nigmatullin
80ff3b3b40 ln: change error messages, extract common code 2022-07-19 17:34:52 +03:00
Andrew Baptist
cc08e1cc3a Update to handle all the latest cargo warnings 2022-07-18 13:20:49 -04:00
Owen Anderson
735db78b3d
wc: specialize scanning loop on settings. (#3708)
* wc: specialize scanning loop on settings.

The primary computational loop in wc (iterating over all the
characters and computing word lengths, etc) is configured by a
number of boolean options that control the text-scanning behavior.
If we monomorphize the code loop for each possible combination of
scanning configurations, the rustc is able to generate better code
for each instantiation, at the least by removing the conditional
checks on each iteration, and possibly by allowing things like
vectorization.

On my computer (aarch64/macos), I am seeing at least a 5% performance
improvement in release builds on all wc flag configurations
(other than those that were already specialized) against
odyssey1024.txt, with wc -l showing the greatest improvement at 15%.

* Reduce the size of the wc dispatch table by half.

By extracting the handling of hand-written fast-paths to the
same dispatch as the automatic specializations, we can avoid
needing to pass `show_bytes` as a const generic to
`word_count_from_reader_specialized`. Eliminating this parameter
halves the number of arms in the dispatch.
2022-07-18 12:16:52 +02:00
dependabot[bot]
d15b95533e
build(deps): bump nix from 0.24.1 to 0.24.2
Bumps [nix](https://github.com/nix-rust/nix) from 0.24.1 to 0.24.2.
- [Release notes](https://github.com/nix-rust/nix/releases)
- [Changelog](https://github.com/nix-rust/nix/blob/v0.24.2/CHANGELOG.md)
- [Commits](https://github.com/nix-rust/nix/compare/v0.24.1...v0.24.2)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-18 06:41:18 +00:00
Niyaz Nigmatullin
4db08273b3 ln: error on --force when src=dst and dst is regular file 2022-07-18 08:17:37 +03:00
Niyaz Nigmatullin
0ea3a735ca
readlink: symlink loop handling (#3717)
readlink: fix symlink loop handling
2022-07-14 22:32:55 +02:00
Sylvestre Ledru
882cd527ff
Merge pull request #3704 from Sciencentistguy/once_cell
Replace lazy_static with once_cell
2022-07-13 16:15:47 +02:00
Daniel Hofstetter
9e44acf307 numfmt: reject suffix if unit is "none" 2022-07-13 10:47:59 +02:00
Sylvestre Ledru
db2e5fc6ec
Merge pull request #3714 from niyaznigmatullin/canonicalize_windows_symlink_loop_looking
canonicalize: Loop looking in windows
2022-07-13 10:36:18 +02:00
Niyaz Nigmatullin
c829ecfd1d uucore/fs: get back to loop looking in windows as FileInformation
for directory is fixed
2022-07-12 17:15:16 +03:00
Jamie Quigley
1a270361c0
Replace lazy_static with once_cell 2022-07-12 14:08:30 +01:00
Daniel Hofstetter
aef24db90f numfmt: show error if "i" suffix is missing 2022-07-12 10:58:07 +02:00
Niyaz Nigmatullin
de65d4d649
Realpath relative options (#3710)
* realpath: introduce relative options, make correct exit codes, make pass
GNU test mist/realpath.sh
2022-07-12 08:29:20 +02:00
Terts Diepraam
6b00aec48e
Merge pull request #3602 from lendandgit/main
df: better error message when executed in a chroot without /proc #3601
2022-07-11 23:02:39 +02:00
Sylvestre Ledru
e239ed9417
Merge pull request #3692 from jfinkels/cp-preserve-perm-link
cp: correctly copy attributes of a dangling symbolic link
2022-07-11 22:50:24 +02:00
Sylvestre Ledru
8074020a8b
Merge pull request #3705 from cakebaker/numfmt_unit
numfmt: implement "--to-unit" & "--from-unit"
2022-07-11 22:46:56 +02:00
Niyaz Nigmatullin
da5808d4ac
ls: add already listed message (#3707)
* ls: handle looping symlinks infinite printing

* ls: better coloring and printing symlinks when dereferenced

* tests/ls: add dereferencing and symlink loop tests

* ls: reformat changed using rustfmt

* ls: follow clippy advice for cleaner code

* uucore/fs: fix FileInformation to open directory handles in Windows as
well
2022-07-11 17:18:58 +02:00
Niyaz Nigmatullin
9d285e953d
Realpath symlinks handling, solves issue #3669 (#3703) 2022-07-10 16:49:25 +02:00
Daniel Hofstetter
1f292dd834 numfmt: implement "--to-unit" & "--from-unit" 2022-07-09 08:01:27 +02:00
Sylvestre Ledru
05823dd619
Merge pull request #3656 from eds-collabora/eds/tee_p
Implement tee -p
2022-07-08 18:41:34 +02:00
leon
de4cfdbea6 stat: improved error message 2022-07-07 15:24:00 +02:00
leon
97998a64dd df: removed unused import 2022-07-07 15:24:00 +02:00
leon
388e14f208 df: error handling cleanup 2022-07-07 15:24:00 +02:00
leon
72b0ba0b05 df: fixed clippy warning 2022-07-07 15:24:00 +02:00
leon
9d554751ca df: better error message when executed in a chroot without /proc #3601 2022-07-07 15:24:00 +02:00
Ed Smith
607bf3ca4d Terminate on elimination of all writers in tee
tee is supposed to exit when there is nothing left to write to. For
finite inputs, it can be hard to determine whether this functions
correctly, but for tee of infinite streams, it is very important to
exit when there is nothing more to write to.
2022-07-07 15:23:50 +02:00
Ed Smith
5c13e88f8b Do not trap pipe errors in yes
This is part of fixing the tee tests. 'yes' is used by the GNU test
suite to identify what the SIGPIPE exit code is on the target
platform. By trapping SIGPIPE, it creates a requirement that other
utilities also trap SIGPIPE (and exit 0 after SIGPIPE). This is
sometimes at odds with their desired behaviour.
2022-07-07 15:23:50 +02:00
Ed Smith
7a961a94a5 Preserve signal exit statuses in timeout
When the monitored process exits, the GNU version of timeout will
preserve its exit status, including the signal state.

This is a partial fix for timeout to enable the tee tests to pass.  It
removes the default Rust trap for SIGPIPE, and kill itself with the
same signal as its child exited with to preserve the signal state.
2022-07-07 15:23:50 +02:00
Ed Smith
a360504574 Implement tee -p and --output-error
This has the following behaviours. On Unix:

- The default is to exit on pipe errors, and warn on other errors.

- "--output-error=warn" means to warn on all errors

- "--output-error", "--output-error=warn-nopipe" and "-p" all mean
  that pipe errors are suppressed, all other errors warn.

- "--output-error=exit" means to warn and exit on all errors.

- "--output-error=exit-nopipe" means to suppress pipe errors, and to
  warn and exit on all other errors.

On non-Unix platforms, all pipe behaviours are ignored, so the default
is effectively "--output-error=warn" and "warn-nopipe" is identical.
The only meaningful option is "--output-error=exit" which is identical
to "--output-error=exit-nopipe" on these platforms.

Note that warnings give a non-zero exit code, but do not halt writing
to non-erroring targets.
2022-07-07 15:23:50 +02:00
Sylvestre Ledru
922afa29ff
Merge branch 'main' into cp-preserve-perm-link 2022-07-07 15:22:57 +02:00
dependabot[bot]
ea503bf633 build(deps): bump regex from 1.5.6 to 1.6.0
Bumps [regex](https://github.com/rust-lang/regex) from 1.5.6 to 1.6.0.
- [Release notes](https://github.com/rust-lang/regex/releases)
- [Changelog](https://github.com/rust-lang/regex/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/regex/compare/1.5.6...1.6.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-07 15:22:48 +02:00
Daniel Hofstetter
ac35a1b985 comm: use NUL if delimiter is empty 2022-07-06 13:50:23 +02:00
Sylvestre Ledru
450bd3b597
Remove the is_symlink function 2022-07-06 11:18:31 +02:00
Sylvestre Ledru
38f5a47f76
Merge pull request #3698 from uutils/dependabot/cargo/once_cell-1.13.0
build(deps): bump once_cell from 1.12.0 to 1.13.0
2022-07-06 08:56:12 +02:00
Sylvestre Ledru
334a0c13ba
Merge branch 'main' into cp-preserve-perm-link 2022-07-05 11:08:55 +02:00
dependabot[bot]
6a335236c1
build(deps): bump once_cell from 1.12.0 to 1.13.0
Bumps [once_cell](https://github.com/matklad/once_cell) from 1.12.0 to 1.13.0.
- [Release notes](https://github.com/matklad/once_cell/releases)
- [Changelog](https://github.com/matklad/once_cell/blob/master/CHANGELOG.md)
- [Commits](https://github.com/matklad/once_cell/compare/v1.12.0...v1.13.0)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-05 06:51:26 +00:00
Sylvestre Ledru
7ca2ae4627
spell: Ignore backport 2022-07-05 08:31:45 +02:00
Sylvestre Ledru
11bbf46647
Only include is_symink for #[cfg(unix)] 2022-07-05 08:30:52 +02:00
Jeffrey Finkelstein
df83d59b2d uucore: add backport for Path::is_symlink()
Add a `uucore::fs::is_symlink()` function that takes in a
`std::path::Path` and decides whether the given path is a symbolic
link. This is essentially a backport of the `Path::is_symlink()`
function that appears in Rust version 1.58.0. This commit also
replaces some now-duplicate code in `chmod`, `cp`, `ln`, and `rmdir`
that checks whether a path is a symbolic link with a call to
`is_symlink()`.

Technically, this commit slightly changes the behavior of
`cp`. Previously, there was a line of code like this

    if fs::symlink_metadata(&source)?.file_type().is_symlink() {

where the `?` operator propagates an error from `symlink_metadata()`
to the caller. Now the line of code is

    if is_symlink(source) {

in which any error from `symlink_metadata()` has been converted to
just be a `false` value. I believe this is a satisfactory tradeoff to
make, since an error in accessing the file will likely cause an error
later in the same code path.
2022-07-04 17:25:52 -04:00
Sylvestre Ledru
480630bfd6
Merge pull request #3696 from cakebaker/numfmt_remove_default_hints_from_help
numfmt: remove duplicate default hints from help
2022-07-04 15:59:07 +02:00
Daniel Hofstetter
bd29a8c472 numfmt: remove duplicate default hints from help 2022-07-04 10:28:47 +02:00
dependabot[bot]
ffd49076d9
build(deps): bump filetime from 0.2.16 to 0.2.17
Bumps [filetime](https://github.com/alexcrichton/filetime) from 0.2.16 to 0.2.17.
- [Release notes](https://github.com/alexcrichton/filetime/releases)
- [Commits](https://github.com/alexcrichton/filetime/commits/0.2.17)

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

Signed-off-by: dependabot[bot] <support@github.com>
2022-07-04 06:36:19 +00:00
Jeffrey Finkelstein
4780690caa cp: copy attributes of dangling symbolic link
Fix a bug in which `cp` incorrectly exited with an error when
attempting to copy the attributes of a dangling symbolic link (that
is, when running `cp -P -p`).

Fixes #3531.
2022-07-03 15:17:00 -04:00
Jeffrey Finkelstein
a7a9da9672 cp: refactor convenience function is_symlink()
Refactor common code used in several places into a convenience
function `is_symlink()` that behaves like `Path::is_symlink()` added
in Rust 1.58.0. (We support earlier versions of Rust so we cannot use
the standard library version of this function.)
2022-07-03 15:17:00 -04:00
Gergely Kalas
4f043ff57f Fix 'wc' gnu test-suite compatibility #3678
This change will extract a utility already present in ls to uucore.
This utility is used by dir and vdir too, which are adjusted to
look it up in uucode. No further changes to ls, dir or dirv intended.

The change here largely fiddles with the output of uu_wc to match
that of GNU wc. This is the case to the extent to make unit tests
pass, however, there are differences remaining. One specific
difference I did not tackle is that GNU wc will not align the
output columns (compute_number_width() -> 1) in the specific case
of the input for --files0-from=- being a named pipe, not real stdin.
This difference can be triggered using the following two invocations.
  - wc --files0-from=- < files0 # use a named pipe, GNU does align
  - cat files0- | wc --files0-from=- # use real stdin, GNU does not
    align.
2022-07-01 16:43:09 +02:00
Sylvestre Ledru
64bc20c2d8
Merge pull request #3686 from cakebaker/show_error_if_padding_is_zero
numfmt: show error if --padding is zero
2022-07-01 15:57:29 +02:00