Commit graph

1237 commits

Author SHA1 Message Date
Sylvestre Ledru
31875a241f touch/gnu compat: 'touch no-file' exit code should be 1 2021-06-02 23:50:35 +02:00
Sylvestre Ledru
eb2c06c37e touch/gnu compat: when touch fails because of a permission error, change the error message
+ return 1 as error code when having this error
2021-06-02 23:48:16 +02:00
Jan Scheer
5898b99627 truncate: add error handling for SIZE argument
* add tests for SIZE argument
* fix clap argument handling for --size and --reference
2021-06-02 22:08:42 +02:00
Jan Scheer
2f5f7c6fa1 split: use "parse_size" from uucore
* make stderr of parsing SIZE/NUMBER argument consistent with GNU's behavior
* add error handling
* add tests
2021-06-02 21:32:41 +02:00
Michael Debertol
ed69d797b5 ln: reject --relative without --symbolic 2021-06-02 21:02:12 +02:00
Michael Debertol
87570bbc10 ln: remove redundant force flag
This information is already encoded in the `OverwriteMode` enum.
2021-06-02 20:56:37 +02:00
Michael Debertol
efa89de463 ln: fix LINK_NAME in help output 2021-06-02 19:58:29 +02:00
Sylvestre Ledru
d8c06dd6bb use clap::crate_version macro instead of the env variable 2021-06-02 19:00:19 +02:00
Michael Debertol
dfaaa8c787 Merge branch 'master' of https://github.com/uutils/coreutils into cp/close-fd 2021-06-02 11:37:37 +02:00
Sylvestre Ledru
132ddf98b6
Merge pull request #2328 from miDeb/seq/validator
seq: reject NaN arguments
2021-06-02 11:20:13 +02:00
Jan Scheer
6b8de1dd8b sort: use "parse_size" from uucore
* make parsing of SIZE argument consistent with GNU's behavior
* add error handling
* add tests
2021-06-02 05:13:57 +02:00
Mitchell Mebane
850a56ccea dircolors: rustfmt 2021-06-01 19:22:17 -05:00
Mitchell Mebane
efe1850087 dircolors: replace getopts with clap
Port argument parsing from getopts to clap.

The only difference I have observed is that clap auto-generates -h and
-V short options for help and version, and there is no way (in clap 2.x)
to disable them.
2021-06-01 19:22:08 -05:00
Michael Debertol
a323e9cda1 cp: show errors in cow on linux 2021-06-01 23:06:38 +02:00
Jan Scheer
a900c7421a od: use "parse_size" from uucore 2021-06-01 22:07:29 +02:00
Michael Debertol
23f89d1494 cp: close file descriptors after cow on linux
Instead of using into_raw_fd(), which transfers ownership and
requires us to close the file descriptor manually,
use as_raw_fd(), which does not transfer ownership to us but drops the
file descriptor when the original file is dropped (in our case at the
end of the function).
2021-06-01 22:04:19 +02:00
Michael Debertol
5329d77cc2 seq: adapt output to GNU seq 2021-06-01 20:35:18 +02:00
Michael Debertol
9b29ac98a5 seq: reject NaN arguments
Move the validation logic to an argument validator.
2021-06-01 18:30:18 +02:00
Michael Debertol
67b83647ac sort: simplify handling of negative zeros
We can simply parse the sign of negative zero as positive, instead of
handling the comparison of zeros differently.
2021-06-01 18:20:24 +02:00
Michael Debertol
06b3092f5f sort: fix debug output for zeros / invalid numbers
We were reporting "no match" when sorting something like "0 ". This is
because we don't distinguish between 0 and invalid lines when sorting.
For debug output we have to get this information back.
2021-06-01 18:18:51 +02:00
Jan Scheer
cc659c8572 Merge branch 'master' of github.com:uutils/coreutils into refactoring_parse_size 2021-06-01 12:35:48 +02:00
Jan Scheer
3c7175f00d head/tail: add fixes and tests for bytes/lines NUM arg (undocumented sign)
* change tail bytes/lines clap parsing to fix posix override behavior
* change tail bytes/lines NUM parsing logic to be consistent with head
2021-06-01 12:17:11 +02:00
Sylvestre Ledru
3625d98fc3
Merge pull request #2326 from tertsdiepraam/ls/hide-ignore-help-text
`ls`: add help text and value name for `--hide` and `--ignore`
2021-06-01 11:41:39 +02:00
Terts Diepraam
1dc4ab92d9 ls: add help text and value name for --hide and --ignore 2021-06-01 10:27:50 +02:00
Sylvestre Ledru
448c8419d3
Merge pull request #2325 from tertsdiepraam/fix-sum-help-text
`sum`: fix help text for System V argument
2021-06-01 10:25:35 +02:00
Terts Diepraam
c1f2d41a27 sum: fix help text for system v argument 2021-06-01 09:54:49 +02:00
Jan Scheer
84f2bff778 head: use "parse_size" from uucore 2021-06-01 09:30:43 +02:00
Sylvestre Ledru
a017c1b589
Merge pull request #2323 from miDeb/maint/spellcheck-all
maint: actually run spellcheck on all files
2021-05-31 23:36:56 +02:00
Sylvestre Ledru
8618771f2e
Merge pull request #2322 from miDeb/seq/improvements
seq: improve compatibility
2021-05-31 23:09:13 +02:00
Michael Debertol
46470fc607 refactor/rmdir: polish spelling 2021-05-31 22:46:06 +02:00
Michael Debertol
41878f1bf4 refactor/pr: polish spelling 2021-05-31 22:46:01 +02:00
Michael Debertol
4cf18e96f3 seq: change default value for -t and remove dubious escape sequences
GNU seq does not support -t, but always outputs a newline at the end.
Therefore, our default for -t should be \n.

Also removes support for escape sequences (interpreting a literal "\n"
as a newline). This is not what GNU seq is doing, and unexpected.
2021-05-31 21:20:19 +02:00
Michael Debertol
c78cc65421 seq: make arguments required
Right now seq panics when invoked without args.
2021-05-31 21:20:19 +02:00
Michael Debertol
6ccc305513 seq: implement integer sequences
If we notice that we can represent all arguments as BigInts, take a
different code path. Just like GNU seq this means we can print an
infinite amount of numbers in this case.
2021-05-31 21:20:12 +02:00
Sylvestre Ledru
badf7aacb7
Merge pull request #2300 from tertsdiepraam/pr
Implement `pr` (resurrection of the resurrected PR)
2021-05-31 21:14:57 +02:00
Sylvestre Ledru
15da98d84e
Merge pull request #2315 from rivy/maint.fmt+spell
Spell check and correct the project
2021-05-31 21:00:04 +02:00
Jan Scheer
8bf1e33b5d Merge branch 'master' of github.com:uutils/coreutils into refactoring_parse_size
* truncate: use "parse_size" from uucore
* workaround fix for "test_reference"
2021-05-31 19:11:06 +02:00
Sylvestre Ledru
8d714b0ab0
Merge pull request #2317 from deantvv/fix-touch-parse-date
Fix touch parse date error
2021-05-31 18:18:44 +02:00
Dean Li
9d8e7b9acb
Fix touch parse date error
Now it can parse `touch -d 2000-01-23 file` and add test for parse date
error.

Related to #2311
2021-05-31 22:04:03 +08:00
Roy Ivy III
3f35e0a421 refactor ~ cargo make format 2021-05-31 08:23:58 -05:00
Roy Ivy III
98aff50d4b docs/tail ~ fix markdownlint complaints 2021-05-31 08:23:58 -05:00
Roy Ivy III
ceda51dd5c docs/ls ~ fix spelling + whitespace 2021-05-31 08:23:58 -05:00
Roy Ivy III
1ca44fbbc3 docs/factor ~ fix markdownlint complaints 2021-05-31 08:23:58 -05:00
Roy Ivy III
b418f19c2d docs/date ~ convert usage text document to a markdown text segment 2021-05-31 08:23:57 -05:00
Roy Ivy III
5c9b474cc8 refactor/whoami ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
dff33a0edb refactor/wc ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
3d42454ebc refactor/users ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
954b3436d9 refactor/truncate ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
f6a079a77f refactor/timeout ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
b1a2f6e044 refactor/tee ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
879ac263bd refactor/test ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
8e824742a1 refactor/stat ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
451110bba0 refactor/split ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
00a2e17c80 refactor/splice ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
f8e04c562b refactor/sort ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
a15f8af99f refactor/shred ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:57 -05:00
Roy Ivy III
13561cb5ae refactor/ptx ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:56 -05:00
Roy Ivy III
324605c78c refactor/printf ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:56 -05:00
Roy Ivy III
aa385cf23c refactor/od ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:56 -05:00
Roy Ivy III
5079972ba6 refactor/nl ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:56 -05:00
Roy Ivy III
00c02505a1 refactor/more ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:23:56 -05:00
Terts Diepraam
7690dc018f Merge branch 'master' into pr 2021-05-31 15:23:06 +02:00
Sylvestre Ledru
13fd02862c
Merge pull request #2316 from deantvv/rmdir-match-gnu-error
rmdir: match GNU error output
2021-05-31 15:23:03 +02:00
Jan Scheer
f9a088cecf du: use "parse_size" from uucore
* fix stderr to be the same than GNU's `du` in case of invalid SIZE
2021-05-31 15:22:37 +02:00
Roy Ivy III
57e342d2b2 refactor/mktemp ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
e3784eff47 refactor/mknod ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
5942ba05ef refactor/ls ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
96faa4efb6 refactor/ln ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
785343db7f refactor/head ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
a481e8230b refactor/hashsum ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
1a37d502d1 refactor/factor ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
ba7939e142 refactor/env ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
6e1bd6027a refactor/du ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
dfe594e918 refactor/date ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
1b1086146b refactor/cp ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
fc5451b5e7 refactor/cksum ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:32 -05:00
Roy Ivy III
43f5c13a7f refactor/chmod ~ polish spelling (comments, names, and exceptions) 2021-05-31 08:11:31 -05:00
Roy Ivy III
9c0c8eb59f change ~ remove 'main.rs' spell-checker exceptions 2021-05-31 08:11:31 -05:00
Terts Diepraam
77a0a077b8 pr: update dependencies 2021-05-31 14:48:12 +02:00
Dean Li
9f1deb2df6
rmdir: match GNU error output
Related to #2258
2021-05-31 19:30:54 +08:00
Sylvestre Ledru
8c5dcd0765
Merge branch 'master' into implement-more 2021-05-31 10:17:15 +02:00
Jan Scheer
3a6605844f uucore: move 'parse_time' to 'parser'
"parse_time" only uses stdlib and does not need to be feature gated.
A more suitable place is the newly created "src/uucore/src/lib/parser/"
2021-05-31 09:54:31 +02:00
Jan Scheer
1c41efd732 stdbuf: use "parse_size" from uucore 2021-05-31 09:35:46 +02:00
Anup Mahindre
898d325aea ls: Fix minor output mismatch
When a single directory is passed to ls in recursive mode, uutils ls
won't print the directory name
======================
GNU ls:
z:
======================
======================
uutils ls:
======================

This commit fixes this minor inconsistency and adds corresponding test.
2021-05-30 18:00:52 +05:30
Sylvestre Ledru
3913731222
Revert "rmdir: match GNU error output" 2021-05-30 09:55:02 +02:00
Sylvestre Ledru
13b2a4afd3
Merge branch 'master' into blake2b_simd 2021-05-30 09:29:40 +02:00
Sylvestre Ledru
83bb8795bd
add a comment to explain the why 2021-05-30 09:16:46 +02:00
Dean Li
5b417e251d
rmdir: match GNU error output
Related to #2258
2021-05-30 10:45:54 +08:00
Terts Diepraam
f9bc80e42c pr: remove comments that are obvious through types 2021-05-30 00:35:40 +02:00
Terts Diepraam
a54fc7a4ba pr: remove unused asref implementations 2021-05-30 00:28:44 +02:00
Michael Debertol
dc63133f14
sort: correctly inherit global flags for keys (#2302)
Closes #2254. We should only inherit global settings for keys when there
are absolutely no options attached to the key.

The default key (matching the whole line) is implicitly added only if no
keys are supplied.

Improved some error messages by including more context.
2021-05-29 23:25:56 +02:00
Michael Debertol
d821719c67
expr: support arbitrary precision integers (#2271)
* expr: support arbitrary precision integers

Instead of i64s we now use BigInts for integer operations. This means
that no result or input can be out of range.
The representation of integer flags was changed from i64 to u8 to make
their intention clearer.

* expr: allow big numbers as arguments as well

Also adds some tests

* expr: use num-traits to check bigints for 0 and 1

* expr: remove obsolete refs

match ergonomics made these avoidable.

* formatting

Co-authored-by: Sylvestre Ledru <sylvestre@debian.org>
2021-05-29 23:25:23 +02:00
Terts Diepraam
bc1870c0a7 Merge branch 'master' into pr 2021-05-29 19:21:31 +02:00
Terts Diepraam
4744b35796 pr: explicit none in match expressions 2021-05-29 19:09:50 +02:00
Terts Diepraam
2e1035b350 pr: static to const 2021-05-29 19:02:42 +02:00
Terts Diepraam
0913a77667 pr: let type inference do its works 2021-05-29 19:01:39 +02:00
Terts Diepraam
12287fcc9c pr: fix clippy lints 2021-05-29 18:44:12 +02:00
Jeffrey Finkelstein
0999b00ff9 truncate: re-organize into one func for each mode
Reorganize the code in `truncate.rs` into three distinct functions
representing the three modes of operation of the `truncate` program. The
three modes are

- `truncate -r RFILE FILE`, which sets the length of `FILE` to match the
  length of `RFILE`,
- `truncate -r RFILE -s NUM FILE`, which sets the length of `FILE`
  relative to the given `RFILE`,
- `truncate -s NUM FILE`, which sets the length of `FILE` either
  absolutely or relative to its curent length.

This organization of the code makes it more concise and easier to
follow.
2021-05-29 15:11:27 +02:00
Jeffrey Finkelstein
5129114ddc truncate: create TruncateMode::to_size() method
Create a method that computes the final target size in bytes for the
file to truncate, given the reference file size and the parameter to the
`TruncateMode`.
2021-05-29 15:11:27 +02:00
Jeffrey Finkelstein
005bc259da truncate: add parse_mode_and_size() helper func
Add a helper function to contain the code for parsing the size and the
modifier symbol, if any. This commit also changes the `TruncateMode`
enum so that the parameter for each "mode" is stored along with the
enumeration value. This is because the parameter has a different meaning
in each mode.
2021-05-29 15:11:27 +02:00
Jeffrey Finkelstein
b898e54d7a truncate: remove read permissions from OpenOptions
Remove "read" permissions from the `OpenOptions` when opening a new file
just to truncate it. We will never read from the file, only write to
it. (Specifically, we will only call `File::set_len()`.)
2021-05-29 15:11:27 +02:00
Gilad Naaman
17b0939dee Moved factor to use clap
Issue: https://github.com/uutils/coreutils/issues/2121
2021-05-29 15:11:27 +02:00
Jan Scheer
e4aa8ee159 users: fix long_help text and clippy warning 2021-05-29 15:11:27 +02:00
Jan Scheer
3aeccfd802 fix a lot of clippy warnings 2021-05-29 15:11:22 +02:00
Terts Diepraam
d94ee87d15 pr: move options into mod 2021-05-29 14:42:24 +02:00
Terts Diepraam
0487360507 pr: make tests compile again 2021-05-29 14:30:30 +02:00
Terts Diepraam
762da0bd37 more: comment out unimplemented arguments 2021-05-29 12:51:47 +02:00
Terts Diepraam
9d17c1fddf more: add todo for unicode width 2021-05-29 12:45:12 +02:00
Terts Diepraam
40ee9023e8 more: simplify main loop 2021-05-29 12:42:46 +02:00
Terts Diepraam
101e55702c more: simplify and fix logic for multiple files 2021-05-29 12:35:03 +02:00
Sylvestre Ledru
3d42d41a72
Merge pull request #2247 from jfinkels/truncate-split-three-functions
truncate: re-organize truncate() into one function for each mode of operation
2021-05-29 10:31:02 +02:00
Sylvestre Ledru
0746b3e1e6
Merge pull request #2292 from Gilnaa/2121-factor-clap
Moved factor to use clap
2021-05-29 10:30:06 +02:00
Jan Scheer
714661774b users: fix long_help text and clippy warning 2021-05-29 02:34:43 +02:00
Jan Scheer
a2947f6897 fix clippy warning 2021-05-29 00:46:25 +02:00
Michael Debertol
bb268d1500
sort: crash when failing to open an input file (#2265)
* sort: crash when failing to open an input file

Instead of ignoring files we fail to open, crash.
The error message does not exactly match gnu, but that would require
more effort.

* use split_whitespace instead of a manual implementation

* fix expected error on windows

* sort: update expected error message
2021-05-28 22:39:33 +02:00
Michael Debertol
e9656a6c32
sort: make GNU test sort-debug-keys pass (#2269)
* sort: disable support for thousand separators

In order to be compatible with GNU, we have to disable thousands
separators. GNU does not enable them for the C locale, either.

Once we add support for locales we can add this feature back.

* sort: delete unused fixtures

* sort: compare -0 and 0 equal

I must have misunderstood this when implementing, but GNU considers
-0, 0, and invalid numbers to be equal.

* sort: strip blanks before applying the char index

* sort: don't crash when key start is after key end

* sort: add "no match" for months at the first non-whitespace char

We should put the "^ no match for key" indicator at the first
non-whitespace character of a field.

* sort: improve support for e notation

* sort: use maches! macros
2021-05-28 22:38:29 +02:00
Jan Scheer
0bf14da490 tail: use "parse_size" from uucore 2021-05-28 22:21:03 +02:00
Jan Scheer
b1b3475e11 truncate: use "parse_size" from uucore 2021-05-28 22:21:03 +02:00
Sylvestre Ledru
a2143dcfbf
Merge pull request #2293 from miDeb/maint-minrustv
maint: adapt code to new MinRustV
2021-05-28 21:48:51 +02:00
Jack O'Connor
80b9bfdd18 switch from blake2-rfc to blake2b_simd 2021-05-28 14:08:46 -04:00
Sylvestre Ledru
fe42808e9b
Merge branch 'master' into implement-more 2021-05-28 19:49:48 +02:00
Terts Diepraam
0a2f74fd8e
More: update crossterm dependency 2021-05-28 19:43:03 +02:00
Michael Debertol
b5cbd506bc maint: remove trailing commas from matches
Trailing commas are only supported starting from 1.48.
2021-05-28 18:58:06 +02:00
Gilad Naaman
6a9ffee548 Moved factor to use clap
Issue: https://github.com/uutils/coreutils/issues/2121
2021-05-28 19:48:28 +03:00
Terts Diepraam
c7930a63f7
Merge pull request #2285 from blesson3/cp-backup-arg-fix
cp: fix regressed issue with `--backup` and `-b`
2021-05-28 18:44:09 +02:00
Michael Debertol
59a42f1254 maint: format recent changes 2021-05-28 18:03:47 +02:00
Michael Debertol
263b122540 maint: use the matches! macro when possible 2021-05-28 18:03:37 +02:00
Terts Diepraam
835a17d79f mktemp: use tempfile instead of custom tempdir 2021-05-27 22:48:10 +02:00
Terts Diepraam
ebe6341ae3 chore: replace tempdir with tempfile 2021-05-27 22:47:03 +02:00
Matt Blessed
41bea72f23 cp: fix regressed issue with --backup and -b
- add test for regressed issue
2021-05-26 18:29:03 -04:00
Matt Blessed
f11f5f3abb mv: refactor backup logic to use shared uucore backup control
- add mv backup tests
2021-05-26 18:23:48 -04:00
Terts Diepraam
b4f6c81810
Merge pull request #2281 from deantvv/chmod-match-gnu-error
chmod: match GNU error
2021-05-26 21:13:05 +02:00
Terts Diepraam
658e52dde0
Merge pull request #2275 from blesson3/cp-backup-support
cp: implement backup support
2021-05-26 21:12:01 +02:00
Matt Blessed
25ed5eeb0e cp: move option check to uumain and use show_usage_error
- add test for conflicting options `--backup` and `--no-clobber`
2021-05-26 11:10:04 -04:00
Dean Li
fe25b51a66
chmod: match GNU error
Related to #2260

Signed-off-by: Dean Li <deantvv@gmail.com>
2021-05-26 22:31:02 +08:00
Terts Diepraam
00dd8d29cb
Merge pull request #2213 from syukronrm/du-clap
du: replace getopts with clap
2021-05-26 16:15:36 +02:00
Syukron Rifail M
eda72b5208 du: replace getopts with clap 2021-05-26 11:23:05 +07:00
Matt Blessed
a8a1ec7faf cp: implement backup control with tests 2021-05-25 23:22:32 -04:00
Yağız can Değirmenci
c78a7937f8 chore: delete show_info macro and replace with show_error 2021-05-26 02:27:10 +03:00
Yağız can Değirmenci
e5e7ca8dc5 fix: simplify logic 2021-05-24 21:20:59 +03:00
Yağız can Değirmenci
991fcc548c fix: log error messages properly on permission errors 2021-05-24 21:07:45 +03:00
Terts Diepraam
da085eca98
Merge pull request #2259 from jfinkels/wc-compute-each-file-and-print
wc: print counts for each file as soon as computed
2021-05-24 17:55:10 +02:00
Michael Debertol
218f523e1b expr: make substr infallible
Instead of returning an Err it should return the "null string"
(in our case that's the empty string) when the offset or length
is invalid.
2021-05-23 22:22:34 +02:00
Sylvestre Ledru
7bf076505f
Merge branch 'master' into who_fix_runlevel 2021-05-23 09:32:37 +02:00
Sylvestre Ledru
b175534a97
Merge pull request #2264 from miDeb/sort-sort-flag
sort: support --sort flag and check for conflicts
2021-05-23 09:30:03 +02:00
Sylvestre Ledru
41bd025d00
Merge pull request #2209 from jfinkels/head-ring-buffer
head: add abstractions for "all but last n lines"
2021-05-23 09:28:17 +02:00
Jeffrey Finkelstein
bc9db289e8 head: add abstractions for "all but last n lines"
Add some abstractions to simplify the `rbuf_but_last_n_lines()`
function, which implements the "take all but the last `n` lines"
functionality of the `head` program. This commit adds

- `RingBuffer`, a fixed-size ring buffer,
- `ZLines`, an iterator over zero-terminated "lines",
- `TakeAllBut`, an iterator over all but the last `n` elements of an
  iterator.

These three together make the implementation of
`rbuf_but_last_n_lines()` concise.
2021-05-22 23:56:48 -04:00
Jeffrey Finkelstein
1f1cd3d966 truncate: re-organize into one func for each mode
Reorganize the code in `truncate.rs` into three distinct functions
representing the three modes of operation of the `truncate` program. The
three modes are

- `truncate -r RFILE FILE`, which sets the length of `FILE` to match the
  length of `RFILE`,
- `truncate -r RFILE -s NUM FILE`, which sets the length of `FILE`
  relative to the given `RFILE`,
- `truncate -s NUM FILE`, which sets the length of `FILE` either
  absolutely or relative to its curent length.

This organization of the code makes it more concise and easier to
follow.
2021-05-22 23:54:39 -04:00
Jeffrey Finkelstein
c6d4d0c07d truncate: create TruncateMode::to_size() method
Create a method that computes the final target size in bytes for the
file to truncate, given the reference file size and the parameter to the
`TruncateMode`.
2021-05-22 23:54:00 -04:00
Jeffrey Finkelstein
544ae87575 truncate: add parse_mode_and_size() helper func
Add a helper function to contain the code for parsing the size and the
modifier symbol, if any. This commit also changes the `TruncateMode`
enum so that the parameter for each "mode" is stored along with the
enumeration value. This is because the parameter has a different meaning
in each mode.
2021-05-22 23:53:59 -04:00
Jeffrey Finkelstein
5eb2a5c3e1 truncate: remove read permissions from OpenOptions
Remove "read" permissions from the `OpenOptions` when opening a new file
just to truncate it. We will never read from the file, only write to
it. (Specifically, we will only call `File::set_len()`.)
2021-05-22 23:45:05 -04:00
Jan Scheer
44c033a013 who: exclude --runlevel from non Linux targets (fix #2239) 2021-05-23 03:05:15 +02:00
Sylvestre Ledru
4aaeede3d8 rustfmt the recent change 2021-05-23 00:13:53 +02:00
Michael Debertol
c1f67ed775 sort: support --sort flag and check for conflicts
`sort` supports three ways to specify the sort mode: a long option
(e.g. --numeric-sort), a short option (e.g. -n) and the sort flag
(e.g. --sort=numeric).
This adds support for the sort flag.

Additionally, sort modes now conflict, which means that an error is
shown when multiple modes are passed, instead of silently picking a mode.
For consistency, I added the `random` sort mode to the `SortMode` enum,
instead of it being a bool flag.
2021-05-22 23:10:41 +02:00
Sylvestre Ledru
726f271273
Merge pull request #2239 from devnexen/fbsd_who_build_fix
who freebsd build fix unsupported RUN_LVL option only for other platf…
2021-05-22 21:34:09 +02:00
Jeffrey Finkelstein
4521aa2659 wc: print counts for each file as soon as computed
Change the behavior of `wc` to print the counts for a file as soon as
it is computed, instead of waiting to compute the counts for all files
before writing any output to `stdout`. The new behavior matches the
behavior of GNU `wc`.

The old behavior looked like this (the word "hello" is entered on
`stdin`):

    $ wc emptyfile.txt -
    hello
	  0       0       0 emptyfile.txt
	  1       1       6
	  1       1       6 total

The new behavior looks like this:

    $ wc emptyfile.txt -
	  0       0       0 emptyfile.txt
    hello
	  1       1       6
	  1       1       6 total
2021-05-22 14:27:37 -04:00
Sylvestre Ledru
73fb426b2b
Merge pull request #2252 from jfinkels/realpath-simplify
realpath: use uucore::fs::canonicalize() to reduce code duplication
2021-05-22 19:10:59 +02:00
David Carlier
fcb079e20e who freebsd build fix unsupported RUN_LVL option only for other platforms. 2021-05-22 18:07:02 +01:00
Sylvestre Ledru
542deb8888
Merge pull request #2246 from miDeb/sort-automatic-extsort
sort: automatically fall back to extsort
2021-05-22 17:21:02 +02:00
Sylvestre Ledru
8055f26a73
Merge pull request #2228 from jfinkels/tail-obo-positive-bytes
tail: fix off-by-one issue for +NUM args
2021-05-22 17:18:55 +02:00
Jeffrey Finkelstein
4b5c3efe85 realpath: use uucore::fs::canonicalize()
Use the `uucore::fs::canonicalize()` function to simplify the
implementation of `realpath`.
2021-05-22 11:18:16 -04:00
Sylvestre Ledru
66cfdb8644
Merge pull request #2143 from nbraud/factor/faster/table
factor::table: Implement a batched version w/ improved performance
2021-05-22 17:18:07 +02:00
Sylvestre Ledru
66dd6dbeff
Merge pull request #2244 from jfinkels/truncate-fix-round-up-character
truncate: fix character used to indicate round up
2021-05-22 14:03:59 +02:00
Michael Debertol
088443276a sort: improve handling of buffer size cmd arg
Instead of overflowing when calculating the buffer size, use
saturating_{pow, mul}.

When failing to parse the buffer size, we now crash instead of silently
ignoring the error.
2021-05-22 14:00:07 +02:00
Sylvestre Ledru
4d3be19de3
Merge pull request #2240 from jhscheer/macos_test_coreutils
who/stat/pinky: adjust tests to be compatible with running on macOS
2021-05-22 12:39:05 +02:00
Sylvestre Ledru
424a99f0e6
Merge pull request #2193 from jfinkels/2186-min-width-stdin
wc: compute minimum width to format counts up front
2021-05-22 12:37:42 +02:00
Michael Debertol
e7da8058dc sort: automatically fall back to extsort
To make this work we make default sort a special case of external sort.

External sorting uses auxiliary files for intermediate chunks. However,
when we can keep our intermediate chunks in memory, we don't write them
to the file system at all. Only when we notice that we can't keep them
in memory they are written to the disk.

Additionally, we don't allocate buffers with the capacity of their
maximum size anymore. Instead, they start with a capacity of 8kb and are
grown only when needed.

This makes sorting smaller files about as fast as it was before
(I'm seeing a regression of ~3%), and allows us to seamlessly continue
with auxiliary files when needed.
2021-05-21 23:09:46 +02:00
Anup Mahindre
414c92eed7 ls: Fix printing paths behavior
For any commandline arguments, ls should print the argument as is (and
not truncate to just the file name)
For any other files it reaches (say through recursive exploration), ls
should print just the filename (as path is printed once when we enter
the directory)
2021-05-21 22:22:28 +05:30
Jan Scheer
007e0a4e7f who/stat/pinky: adjust tests to be compatible with running on macOS
A lot of tests depend on GNU's coreutils to be installed in order
to obtain reference values during testing.
In these cases testing is limited to `target_os = linux`.
This PR installs GNU's coreutils on "github actions" and adjusts the
tests for `who`, `stat` and `pinky` in order to be compatible with macOS.

* `brew install coreutils` (prefix is 'g', e.g. `gwho`, `gstat`, etc.
* switch paths for testing to something that's available on both OSs,
    e.g. `/boot` -> `/bin`, etc.
* switch paths for testing to the macOS equivalent,
    e.g. `/dev/pts/ptmx` -> `/dev/ptmx`, etc.
* exclude paths when no equivalent is available,
    e.g. `/proc`, `/etc/fstab`, etc.
* refactor tests to make better use of the testing API
* fix a warning in utmpx.rs to print to stderr instead of stdout
* fix long_usage text in `who`
* fix minor output formatting in `stat`

* the `expected_result` function should be refactored
    to reduce duplicate code
* more tests should be adjusted to not only run on `target_os = linux`
2021-05-21 11:55:20 +02:00
Sylvestre Ledru
df45b20dc1
Merge pull request #2243 from jfinkels/truncate-min-max
truncate: use min() and max() instead of if/else statements
2021-05-21 10:09:43 +02:00
Jeffrey Finkelstein
a23555e857 truncate: fix character used to indicate round up
Fix a bug in which the incorrect character was being used to indicate
"round up to the nearest multiple" mode. The character was "*" but it
should be "%". This commit corrects that.
2021-05-20 23:19:58 -04:00
Jeffrey Finkelstein
17b95246cd truncate: use min() and max() instead of if stmts 2021-05-20 21:24:43 -04:00
Jeffrey Finkelstein
fc29846b45 truncate: fix error message for file not found
Change the error message for when the reference file (the `-r` argument)
is not found to match GNU coreutils. This commit also eliminates a
redundant call to `File::open`; the file need not be opened because the
size in bytes can be read from the result of `std::fs::metadata()`.
2021-05-20 20:59:59 -04:00
Sylvestre Ledru
efb781f59a
Merge pull request #2221 from jfinkels/head-display-multiple-errors-2
head: display errors for each input file instead of terminating at the first error
2021-05-20 23:24:35 +02:00
Sylvestre Ledru
ca196a6dad
Merge pull request #2218 from miDeb/sort-chunks
sort: read files as chunks, off-thread
2021-05-20 23:24:02 +02:00
nicoo
a0a103b15e factor::table::chunked: Add test (equivalent to the single-number version) 2021-05-20 17:01:33 +02:00
nicoo
998b3c11d3 factor: Make random Factors instance generatable for tests 2021-05-20 17:00:49 +02:00
Jeffrey Finkelstein
63b496eaa8 truncate: refactor parse_size() function
Change the interface provided by the `parse_size()` function to reduce
its responsibilities to just a single task: parsing a number of bytes
from a string of the form '123KB', etc. Previously, the function was
also responsible for deciding which mode truncate would operate in.

Furthermore, this commit simplifies the code for parsing the number and
unit to be less verbose and use less mutable state.

Finally, this commit adds some unit tests for the `parse_size()`
function.
2021-05-19 23:07:11 -04:00
Sylvestre Ledru
cacd078a49
Merge pull request #2227 from jfinkels/tail-iocopy-bounded-tail
tail: use std::io::copy() to write bytes to stdout
2021-05-18 20:42:59 +02:00
Jan Scheer
ce5b852a31 stat: remove unused/duplicate tests 2021-05-18 19:58:33 +02:00
Arijit Dey
1596c65dfd
Downgrade crossterm version 2021-05-18 22:29:59 +05:30
Arijit Dey
7a88df9fb4
Fix broken terminal in tests 2021-05-18 12:42:33 +05:30
Jeffrey Finkelstein
bc29645531 tail: fix off-by-one issue for +NUM args
Fix an off-by-one issue for `tail -c +NUM` and `tail -n +NUM` command
line options.
2021-05-17 19:45:42 -04:00
Jeffrey Finkelstein
fea1026669 tail: use std::io::copy() to write bytes to stdout 2021-05-17 18:15:39 -04:00
nicoo
00322b986b factor: Move benchmarks out-of-crate 2021-05-17 19:43:38 +02:00
nicoo
1cd001f529 factor::benches::table: Match BenchmarkId w/ criterion's conventions
See https://bheisler.github.io/criterion.rs/book/user_guide/comparing_functions.html
2021-05-17 19:43:38 +02:00
nicoo
7c649bc74e factor::benches: Add check against ASLR 2021-05-17 19:43:38 +02:00
nicoo
ddfcd2eb14 factor::benchmarking: Add wishlist / planned work 2021-05-17 19:43:38 +02:00
nicoo
1d75f09743 factor::benchmarking(doc): Add guidance on writing µbenches 2021-05-17 19:43:38 +02:00
nicoo
e9f8194266 factor::benchmarking(doc): Add guidance on running µbenches 2021-05-17 19:43:38 +02:00
nicoo
ae15bf16a8 factor::benches::table: Report throughput (in numbers/s) 2021-05-17 19:43:38 +02:00
nicoo
12efaa6add factor: Add BENCHMARKING.md 2021-05-17 19:43:38 +02:00
nicoo
7c287542c7 factor::table: Fixup microbenchmark
Previous version would perform an amount of work proportional to `CHUNK_SIZE`,
so this wasn't a valid way to benchmark at multiple values of that constant.

The `TryInto` implementation for `&mut [T]` to `&mut [T; N]` relies on `const`
generics, and is available in (stable) Rust v1.51 and later.
2021-05-17 19:43:38 +02:00
nicoo
1fd5f9da25 factor::table::factor_chunk: Turn loop inside-out
This keeps the traversal of `P_INVS_U64` (a large table) to a single pass
in-order, rather than `CHUNK_SIZE` passes.
2021-05-17 19:43:38 +02:00
nicoo
cd047425aa factor::table: Add chunked implementation and microbenchmarks
The factor_chunk implementation is a strawman, but getting it in place allows us
to set up the microbenchmarking etc.
2021-05-17 19:43:38 +02:00
nicoo
c68c83c6dd factor::table: Take mutable refs
This will be easier to adapt to working with multiple numbers to process at once.
2021-05-17 19:43:38 +02:00
Jeffrey Finkelstein
eeef8290df head: display errors for each input file
Change the behavior of `head` to display an error for each problematic
file, instead of displaying an error message for the first problematic
file and terminating immediately at that point. This change now matches
the behavior of GNU `head`.

Before this commit, the first error caused the program to terminate
immediately:

    $ head a b c
    head: error: head: cannot open 'a' for reading: No such file or directory

After this commit:

    $ head a b c
    head: cannot open 'a' for reading: No such file or directory
    head: cannot open 'b' for reading: No such file or directory
    head: cannot open 'c' for reading: No such file or directory
2021-05-17 08:19:47 -04:00
Michael Debertol
fcd48813e0 sort: read files as chunks, off-thread
Instead of using a BufReader and reading each line separately,
allocating a String for each one, we read to a chunk. Lines are
references to this chunk. This makes the allocator's job much easier
and yields performance improvements.

Chunks are read on a separate thread to further improve performance.
2021-05-16 21:13:37 +02:00
Arijit Dey
c930509095
Fix clippy warning 2021-05-16 22:30:46 +05:30
Arijit Dey
22ba21d8ab
Fix bug with terminal getting weird 2021-05-16 22:26:54 +05:30