Commit graph

1839 commits

Author SHA1 Message Date
Thomas Queiroz
e2fa6f9412
users: use UResult 2021-10-04 19:53:46 -03:00
Thomas Queiroz
00c9710206
uucore_procs+uu: specify uucore::show_error
This allows crates to use `#[uucore_procs::gen_uumain]` without `use uucore::show_error` or

    #[macro_use]
    extern crate uucore;

Removed unecessary usage
2021-10-04 19:53:16 -03:00
Sylvestre Ledru
368fa54520
Merge pull request #2703 from thomasqueirozb/base_uresult
base32 + base64 + basenc: use UResult
2021-10-03 17:34:56 +02:00
Thomas Queiroz
b924774c8a
basenc: use UResult 2021-10-02 23:17:16 -03:00
Thomas Queiroz
452329ad19
base64: use UResult 2021-10-02 23:15:40 -03:00
Thomas Queiroz
97df700d67
base32: use UResult 2021-10-02 23:12:09 -03:00
Thomas Queiroz
9dd401c358
base32: base_common use UResult 2021-10-02 23:10:00 -03:00
vulppine
d5caa0d9d8 seq: Adds hexadecimal integer parsing 2021-10-02 08:15:25 -07:00
Jeffrey Finkelstein
548a5121ae dd: use assert! instead of if then panic! 2021-10-02 10:15:15 -04:00
Jeffrey Finkelstein
6aee05a0f1 od: use assert! instead of if then panic! 2021-10-02 09:46:43 -04:00
Jeffrey Finkelstein
de158c0122 sort: replace redundant closure with function itself 2021-10-02 09:46:43 -04:00
Jeffrey Finkelstein
06ae968ecf csplit: use assert! instead of if then panic! 2021-10-02 09:46:43 -04:00
Jeffrey Finkelstein
71b7d6b57d more: remove redundant mut from stdout accesses 2021-10-02 09:46:43 -04:00
Jeffrey Finkelstein
d013461a6f ls: replace redundant closure with function itself 2021-10-02 09:46:43 -04:00
Sylvestre Ledru
b2fa51ddd9
Merge pull request #2656 from jhscheer/ls_selinux
`ls`: add support for showing SELinux context (--context/-Z)
2021-10-02 12:56:09 +02:00
vulppine
4319248bb6 cp: Changes '1' to 'EXIT_ERR' in UError impl 2021-10-01 16:45:19 -07:00
vulppine
c64f09dc59 cp: Adds a needed macro, changes a return 2021-10-01 15:18:05 -07:00
vulppine
4ff5fea502 cp: uumain returns UResult, UError for Error 2021-10-01 14:58:26 -07:00
Sylvestre Ledru
01d098993b
Merge pull request #2662 from Smicry/master
add kill -l final new line #2644
2021-09-29 09:58:50 +02:00
Thomas Queiroz
3882df5cdc
expr: use UResult 2021-09-25 15:36:04 -03:00
Jan Scheer
8cd8c25b0d
ls: silence clippy warnings if feat_selinx is not set 2021-09-22 13:49:08 +02:00
Jan Scheer
8f229aad87
ls: move SELinux String building logic to its own function 2021-09-22 12:24:27 +02:00
Jan Scheer
8c0b7d1314
chroot: move logic so it can be triggered by tests
* move the command building logic before the `chroot` syscall so it
will be reachable by tests that don't have root permissions.
2021-09-22 11:59:43 +02:00
Raphaël Thériault
6931dd11f1 Use non-yanked version of digest crate in hashsum 2021-09-19 12:38:56 -07:00
Jan Scheer
94fbe1edef
chroot: quick fix for #2687
* fixes #2687
* change error message to better mimic GNU
2021-09-19 13:58:44 +02:00
Sylvestre Ledru
8d418cd61c
Merge pull request #2672 from oeble/kill_with_signal_name
Kill with signal name
2021-09-18 22:55:27 +02:00
Sylvestre Ledru
3e8b4045c8
Merge pull request #2675 from blyxxyz/whoami-cleanup
whoami: Cleanup
2021-09-18 17:20:09 +02:00
Sylvestre Ledru
b59bbddcbf
Merge pull request #2663 from jfinkels/hashsum-std-io-copy
hashsum: use std::io::copy() to simplify digest
2021-09-18 17:19:16 +02:00
Jan Verbeek
7ea2bfbe26 seq: replace loops with a single format string
Replace two loops that print leading and trailing 0s when printing a
number in fixed-width mode with a single call to `write!()` with the
appropriate formatting parameters.
2021-09-18 10:27:03 -04:00
Jeffrey Finkelstein
bfb1327ad4 seq: use print_seq_integers() regardless of last
Ensure that the `print_seq_integers()` function is called when the first
number and the increment are integers, regardless of the type of the
last value specified.
2021-09-18 10:27:03 -04:00
Sylvestre Ledru
522d4d39e3
Merge pull request #2680 from blyxxyz/utmpx-safety
uucore::utmpx: Make thread-safe
2021-09-18 16:15:52 +02:00
Jeffrey Finkelstein
7fea771f32 hashsum: use std::io::copy() to simplify digest
Create a `DigestWriter` struct that implements `Write` by passing bytes
directly to `Digest::input()`, so that `hashsum` can use
`std::io::copy()`. Using `std::io::copy()` eliminates some boilerplate
code around reading and writing bytes. And defining `DigestWriter` makes
it easier to add a `#[cfg(windows)]` guard around the Windows-specific
replacement of "\r\n" with "\n".
2021-09-18 09:51:33 -04:00
Jeffrey Finkelstein
3854a97749 seq: remove unused Number::num_digits() function
Remove the `Number::num_digits()` function in favor of the
`digits::num_integral_digits()` functions.
2021-09-17 23:50:13 -04:00
Jeffrey Finkelstein
2ac5dc0a70 seq: compute correct width for scientific notation
Change the way `seq` computes the number of digits needed to print a
number so that it works for inputs given in scientific notation.
Specifically, this commit parses the input string to determine whether
it is an integer, a float in decimal notation, or a float in scientific
notation, and then computes the number of integral digits and the number
of fractional digits based on that. This also supports floating point
negative zero, expressed in both decimal and scientific notation.
2021-09-17 23:49:54 -04:00
Jan Scheer
79d838b1c3
Merge branch 'master' into ls_selinux 2021-09-17 14:14:47 +02:00
Sylvestre Ledru
88a689075c
Merge pull request #2682 from jfinkels/seq-simpler-terminator-check
seq: add is_first_iteration to avoid comparisons
2021-09-17 12:19:05 +02:00
Sylvestre Ledru
3d867fcf7c
Merge pull request #2684 from blyxxyz/hostname-cleanup
hostname: Cleanup
2021-09-16 22:22:34 +02:00
Jan Verbeek
5bb56ec528
whoami: Restrict scope of unsafe
Co-authored-by: Jan Scheer <jhscheer@users.noreply.github.com>
2021-09-15 15:37:15 +02:00
Jan Verbeek
3f37ddbd22 hostname: Cleanup
- Attach context to I/O errors
- Make flags override each other
- Support invalid unicode as argument
- Call WsaCleanup() even on panic
- Do not use deprecated std::mem::uninitialized()
2021-09-15 13:45:02 +02:00
Sylvestre Ledru
7eaae75bfc add a github action job to identify unused deps 2021-09-15 12:06:50 +02:00
Jeffrey Finkelstein
53a91be2df seq: add is_first_iteration to avoid comparisons
Add the `is_first_iteration` Boolean variable to the `print_seq()`
function in order to avoid unnecessary comparisons. Specifically, before
this change, the `done_printing()` function was called twice on each
iteration of the main loop. After this change, it is only called once
per iteration.

Furthermore, this change makes the `print_seq()` function similar in
structure to the `print_seq_integers()` function.

Co-authored-by: Jan Verbeek <jan.verbeek@posteo.nl>
2021-09-14 20:57:38 -04:00
Jan Verbeek
519c0d16b3 uucore::utmpx: Make thread-safe 2021-09-14 21:17:50 +02:00
Michael Debertol
5c97c1ccc4
Merge pull request #2678 from blyxxyz/io-error-detect-os
Do not discard non-OS error messages
2021-09-14 20:21:48 +02:00
Jan Verbeek
1edd2bf3a8 Do not discard non-OS error messages 2021-09-14 15:11:54 +02:00
Jeffrey Finkelstein
60025800c3 seq: trim leading whitespace from inputs 2021-09-13 21:46:17 -04:00
Jan Verbeek
4555c85564 whoami: Cleanup
- Use modern conventions
- Restrict the scope of unsafe
- Do not use deprecated `std::mem::unitialized()`
- Do not bake unicode into design
2021-09-13 22:54:45 +02:00
Sylvestre Ledru
e9d63519dd
Merge pull request #2668 from sylvestre/unused-deps
Remove plenty of unused deps
2021-09-13 21:45:39 +02:00
Michael Debertol
570f23ac90
Merge pull request #2647 from jfinkels/seq-test-inf
seq: use stdout.write_all() instead of print!()
2021-09-13 18:34:24 +02:00
Sylvestre Ledru
a74e4bf095 shred: remove the unused dep on filetime 2021-09-13 18:15:51 +02:00
Sylvestre Ledru
a6c235bcd1 csplit: remove the unused dep on glob 2021-09-13 18:15:51 +02:00
Sylvestre Ledru
826c948234 ls: remove the unused dep on locale 2021-09-13 18:15:51 +02:00
Sylvestre Ledru
2d67252dc4 rm: only set the winapi dep on Windows 2021-09-13 18:15:51 +02:00
Sylvestre Ledru
cca2b19b4e tail: only set the winapi dep on Windows 2021-09-13 18:15:49 +02:00
Michael Debertol
5faa4c41db
Merge pull request #2607 from jfinkels/tac-regex
tac: add support for --regex option to tac
2021-09-13 18:12:57 +02:00
Sylvestre Ledru
87b6aa89e3
pr: remove unused "time" dep (#2667) 2021-09-13 18:08:51 +02:00
Sylvestre Ledru
68df4de1a2
nice: update to use the same version of nix as other programs (#2666) 2021-09-13 18:08:41 +02:00
Sylvestre Ledru
ebe897e4d4
shred: remove unused "time" dep (#2665) 2021-09-13 18:05:06 +02:00
Jan Scheer
4dc6536bb9
Merge branch 'master' into ls_selinux 2021-09-13 13:42:51 +02:00
Jan Scheer
cd2153eac6
ls: (--context/-Z) add support for invalid utf8
If security context byte slice contains invalid utf8:
* issue warning
* show replacement characters for invalid utf8 sequences
2021-09-13 13:24:44 +02:00
Sylvestre Ledru
b4f45bcc1a
Merge pull request #2664 from jfinkels/wc-remove-mut-width
wc: remove mutable min_width parameter
2021-09-13 08:25:46 +02:00
Jan Verbeek
3e0b3c93ef mktemp: Do not use unsafe 2021-09-12 21:50:36 +02:00
Jeffrey Finkelstein
7ec6452265 wc: remove mutable min_width parameter
Remove mutability from the `min_width` parameter to the `print_stats()`
function in `wc`.
2021-09-12 12:25:52 -04:00
Smicry
7e577476d8 add kill -l final new line #2644 2021-09-12 23:20:05 +08:00
Jan Verbeek
4a20ef1850 chcon: Remove unused Options.dereference to fix Clippy 2021-09-12 13:17:55 +02:00
Sylvestre Ledru
447d6f2b61
Merge pull request #2654 from blyxxyz/dedup-splice
Move common pipe and splice functions into uucore
2021-09-12 09:23:05 +02:00
Jeffrey Finkelstein
664c7a6ec5 tac: add support for --regex option to tac
Add support for `tac --regex`, where the line separator is interpreted
as a regular expression.
2021-09-11 22:54:55 -04:00
Olivier EBLÉ
df64c19107
kill: kill old form with signal name
This commit aim to correct #2645.
The origin of the problem was that `handle_obsolete` was not looking for
named signals but only for numbers preceded by '-'. I have made a few
changes:

- Change `handle_obsolete` to use `signal_by_name_or_value` to parse the
  possible signal.
- Since now the signal is already parsed return an `Option<usize>`
  instead of `Option<&str>` to parse later.
- Change the way to decide the pid to use from a `match` to a `if`
  because the tested element are actually not the same for each branch.
- Parse the signal from the `-s` argument outside of `kill` function for
  consistency with the "obsolete" signal case.
- Again for consistency, parse the pids outside the `kill` function.
2021-09-12 00:44:11 +02:00
Jan Scheer
e018a45b54
test_ls: add/adjust tests for SELinux context 2021-09-11 04:13:30 +02:00
Jeffrey Finkelstein
96b8616a1a seq: use stdout.write_all() instead of print!()
Change from using `print!()` to using `stdout.write_all()` in order to
allow the main function to handle broken pipe errors gracefully.
2021-09-10 20:00:26 -04:00
Jan Verbeek
b7d697753c unlink: Simplify, remove unsafe, move to core
This makes it no longer possible to pass multiple filenames, but every
other implementation I tried (GNU, busybox, FreeBSD, sbase) also
forbids that so I think it's for the best.
2021-09-10 21:50:38 +02:00
Jan Scheer
fe3645d4d5
ls: add support for showing SELinux context (--context/-Z) 2021-09-10 21:33:34 +02:00
Jan Verbeek
23647be07a cat: Use larger splice size
This raises performance by 10-20% or so.
2021-09-10 21:24:34 +02:00
Jan Verbeek
d002810a47 cat: Do not assume complete writes 2021-09-10 21:24:34 +02:00
Jan Verbeek
c1079e0b1c Move common pipe and splice functions into uucore
This cuts down on repetitive unsafe code and repetitive code in
general.
2021-09-10 21:24:34 +02:00
Jan Verbeek
91d39de16e sort: derive Default impl for FieldSelector 2021-09-10 19:25:54 +02:00
Jeffrey Finkelstein
fc77e51b64 printf: derive Default impl for FormatPrimitive 2021-09-10 19:24:59 +02:00
Jan Verbeek
d05410383f chown: Fix clippy warning to fix CI 2021-09-10 18:56:31 +02:00
Sylvestre Ledru
75e5c42e40
chown: support '.' as 'user.group' separator (like ':') (#2638)
* chown: support '.' as 'user.group' separator (like ':')

It also manages the case:
user.name:group (valid too)

Should fix:
gnu/tests/chown/separator.sh
2021-09-10 08:15:23 +02:00
Sylvestre Ledru
ed258e3c9c
touch: add --ref as an alias (#2641) 2021-09-09 21:48:17 +02:00
Michael Debertol
2170d81621
Merge pull request #2633 from blyxxyz/update-quoting
Update filename quoting and printing
2021-09-09 20:42:00 +02:00
Michael Debertol
37c6b794c8
Merge pull request #2646 from 353fc443/uresult-uptime
uptime: added UResult
2021-09-09 20:32:06 +02:00
353fc443
e4aad6d971
uptime: added UResult 2021-09-09 17:59:02 +00:00
Jan Scheer
cd0d23752a
tail: add fixes to pass "gnu/tests/tail-2/tail-c.sh" from GNU's test suite 2021-09-08 13:10:19 +02:00
Sylvestre Ledru
ff5607c363
Merge pull request #2622 from tertsdiepraam/ls/special-chars-in-double-quotes
`ls`: always use single quotes when `$`, `\` or ` are present in a filename
2021-09-07 22:04:48 +02:00
Jan Verbeek
1ef2574b08 Replace backtick quoting 2021-09-07 20:16:45 +02:00
Jan Verbeek
918603909b Update hashsum quoting FIXME instructions 2021-09-07 20:15:54 +02:00
Jan Verbeek
6d346b2307 Replace manual formatting by show_error!()/show_warning!() 2021-09-07 20:15:54 +02:00
Jan Verbeek
259f18fcab Update message quoting and filename printing 2021-09-07 19:49:01 +02:00
Jan Verbeek
60df3c6b7c uucore: Cache args_os(), util_name(), execution_phrase()
And remove args() because there's no valid use for it, invalid unicode
handling is specified in a different way.
2021-09-07 18:51:25 +02:00
353fc443
06ff6ac4f1
whoami: Added UResult 2021-09-07 08:10:06 +00:00
Sylvestre Ledru
a0be9811c6
Merge pull request #2513 from drocco007/test-parentheses
test: handle additional parentheses edge cases
2021-09-06 22:23:21 +02:00
Sylvestre Ledru
17a435c7a6
Fix clippy warnings 2021-09-06 20:42:14 +02:00
Sylvestre Ledru
90fd900b8f
Fix clippy warnings in test.rs 2021-09-06 20:41:41 +02:00
James Robson
625c3f2330 Add -e/-m to realpath 2021-09-05 22:50:23 +02:00
Mahmoud Soltan
9bc14a239c
Added support for ls -l --color to color symlink targets as well. (#2627)
* Fixed some documentation of display_item_long that was missed in #2623

* Implemented coloring of `ls -l` symlink targets( after the arrow `->`).

* Documented display_file_name to some extent.

* Ran rustfmt as part of mitigating CI chain errors.

* Removed unused variables and code in test_ls_long_format as per #2623

specifically, as per
https://github.com/uutils/coreutils/pull/2623#pullrequestreview-742386707

* Added a thorough test for `ls -laR --color` symlink coloring implemented in this branch.

* renamed test files and dirs to shorter names and ran rustfmt.

* Changed the order with which files are expected to match the change in their name.

* Bettered some comments.

* Removed needless borrow. Fixed that one clippy warning.

* Moved the cfg not windows up to the function level

because this function is meant to only run in non-windows OS (with
groups and unames).

Fixes the unused variable warning in CI.
2021-09-05 13:25:56 +02:00
Sylvestre Ledru
6226a03214
Merge pull request #2624 from miDeb/cp/acl
cp: correctly copy mode, ownership, acl and context
2021-09-03 20:18:13 +02:00
Sylvestre Ledru
499f10ca1f
Merge branch 'master' into ls/special-chars-in-double-quotes 2021-09-03 09:00:54 +02:00
Michael Debertol
a4fca2d4fc uucore/perms: remove flags in favor of enums
Part of the code was transliterated from GNU's implementation in C,
and used flags to store settings. Instead, we can use enums to avoid
magic values or binary operations to extract flags.
2021-09-03 00:50:04 +02:00
Michael Debertol
195f827cd4 chown/chgrp: share more code
Also share argument parsing code between `chgrp` and `chown`
2021-09-03 00:50:04 +02:00
Michael Debertol
a517671d55
Merge pull request #2621 from blyxxyz/filename-quoting
Implement proper quoting/escaping for filenames
2021-09-01 14:15:44 +02:00