Commit graph

1237 commits

Author SHA1 Message Date
Roy Ivy III
9f2cb2e5e9 refactor/hashsum ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:23 -05:00
Roy Ivy III
2bf06c3104 refactor/fold ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:23 -05:00
Roy Ivy III
28e176cbba refactor/expr ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:23 -05:00
Roy Ivy III
489f9e8386 refactor/expand ~ fix cargo clippy complaint (clippy::manual_str_repeat) 2021-06-06 19:28:23 -05:00
Roy Ivy III
122d82e835 refactor/expand ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:23 -05:00
Roy Ivy III
9964a21fe3 refactor/env ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:23 -05:00
Roy Ivy III
b08c568748 refactor/echo ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:23 -05:00
Roy Ivy III
3409dc93e3 refactor/du ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:23 -05:00
Roy Ivy III
14bb9ec616 refactor/csplit ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:22 -05:00
Roy Ivy III
1e418e8d84 refactor/chroot ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:22 -05:00
Roy Ivy III
baa656ca8a refactor/chown ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:22 -05:00
Roy Ivy III
35b360b8e4 refactor/chmod ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:22 -05:00
Roy Ivy III
c115ad4274 refactor/cat ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:22 -05:00
Roy Ivy III
777e3906f8 refactor/basename ~ fix cargo clippy complaint (clippy::needless_borrow) 2021-06-06 19:28:22 -05:00
Roy Ivy III
c192550f22 refactor ~ polish spelling + add spelling exceptions 2021-06-06 19:28:22 -05:00
Roy Ivy III
1ef820212c refactor/rm ~ fix cargo clippy warning (clippy::upper_case_acronyms) 2021-06-06 19:17:18 -05:00
Roy Ivy III
3cfb956684 refactor/du ~ fix cargo clippy warning (clippy::ptr_arg) 2021-06-06 19:17:18 -05:00
Jan Scheer
12de58aec0 Merge branch 'master' of github.com:uutils/coreutils into refactoring_parse_size 2021-06-06 22:54:02 +02:00
Jan Scheer
884f570125 du/od/sort: refactor - replace map_or_else with unwrap_or_else 2021-06-06 21:55:39 +02:00
Sylvestre Ledru
a3b520abde
Merge pull request #2363 from sylvestre/doc-hashsum
hashsum: document how to benchmark blake2
2021-06-06 21:28:23 +02:00
Michael Debertol
d6da143c4e sort: ignore errors when waiting for child 2021-06-06 19:53:28 +02:00
Michael Debertol
7c9da82b39 sort: implement --batch-size 2021-06-06 18:01:08 +02:00
Michael Debertol
8d213219c7 sort: implement --compress-program 2021-06-06 18:01:08 +02:00
Michael Debertol
5a5c7c5a34 sort: properly check for empty reads 2021-06-06 18:01:08 +02:00
Michael Debertol
66359a0f56 sort: insert line separators after non-empty files
If files don't end witht a line separator we have to insert one,
otherwise the last line will be combined with the first line of the next
file.
2021-06-06 18:01:08 +02:00
Michael Debertol
2dd6824e76 sort: never use a bigger buffer than requested
A min buffer size of 8KB makes sense in practice, but decreases testability.
2021-06-06 18:01:08 +02:00
Sylvestre Ledru
7f07bd82d4 hashsum: document how to benchmark blake2 2021-06-06 13:26:45 +02:00
Sylvestre Ledru
27456fc8fb
Merge pull request #2296 from oconnor663/blake2b_simd
switch from blake2-rfc to blake2b_simd
2021-06-06 13:14:39 +02:00
Terts Diepraam
6324df890f
Merge pull request #2357 from deantvv/more-show-next-file
more: Show next file at bottom line
2021-06-06 10:52:03 +02:00
Dean Li
b9fe76ab92
more: Show next file at bottom line
Implement feature requested in #2318.
2021-06-06 09:26:47 +08:00
Sylvestre Ledru
9ae3c7634c
Merge pull request #2354 from tertsdiepraam/more/fix-not-showing-last-line
`more`: Do not accidentically hide last line
2021-06-05 16:05:43 +02:00
Terts Diepraam
2760efb01d more: fix test 2021-06-05 14:42:43 +02:00
Terts Diepraam
420e9322ea more: do not accidentically hide last line 2021-06-05 14:07:09 +02:00
Sylvestre Ledru
285b27c9b3 du: add --app as alias of --apparent-size to match GNU 2021-06-05 11:04:42 +02:00
Sylvestre Ledru
4143e3f54f
Merge pull request #2332 from mitchellmebane/dircolors-clap
dircolors: replace getopts with clap
2021-06-05 10:12:57 +02:00
Sylvestre Ledru
9712ecb4d5
Merge pull request #2340 from deantvv/more-unicode
more: fix unicode bug
2021-06-04 19:51:32 +02:00
Michael Debertol
e7fa6715a7 Merge branch 'master' of https://github.com/uutils/coreutils into ln/dst-symlink 2021-06-04 19:42:19 +02:00
Dean Li
acd290d11f
more: fix unicode bug for breakline
- Use `unicode_segmentation` and `unicode_width` to determine proper `break_line` position.
- Keep track of total_width as suggested by @tertsdiepraam.
- Add unittest for ZWJ unicode case

Related to #2319.
2021-06-04 22:06:27 +08:00
Jan Scheer
f8e96150f8 fix clippy warnings and spelling
* add some missing LICENSE headers
2021-06-04 15:39:34 +02:00
Mitchell Mebane
754082886c dircolors: Address code review comments 2021-06-03 20:49:25 -05:00
Jan Scheer
130bf49e5d Merge branch 'master' of github.com:uutils/coreutils into refactoring_parse_size 2021-06-03 22:32:34 +02:00
Sylvestre Ledru
6a8d15f92e gnu/rm: match gnu's output 2021-06-03 22:19:14 +02:00
Jan Scheer
db3ee61742 du/sort/od/stdbuf: make error handling of SIZE/BYTES/MODE arguments more consistent
* od: add stderr info for not yet implemented '--strings' flag
2021-06-03 21:00:03 +02:00
Jan Scheer
ad26b7a042 head/tail/split: make error handling of NUM/SIZE arguments more
consistent

* add tests for each flag that takes NUM/SIZE arguments
* fix bug in tail where 'quiet' and 'verbose' flags did not override each other POSIX style
2021-06-03 20:37:29 +02:00
Michael Debertol
6c46d09397 ln: canonicalize the parent directory of dst, not dst
dst may or may not exist. In case it exists it might already be a symlink.
In neither case we should try to canonicalize dst, only its parent directory.

https://www.gnu.org/software/coreutils/manual/html_node/ln-invocation.html
> Relative symbolic links are generated based on their canonicalized
> **containing directory**, and canonicalized targets.
2021-06-03 19:10:22 +02:00
Michael Debertol
af8f47ea6a ln: remove redundant check
if `dst.exists()` and `settings.overwrite` is `OverwriteMode::Force`,
we already delete the file in the match above.
2021-06-03 16:30:45 +02:00
Sylvestre Ledru
841b689477
Merge pull request #2334 from sylvestre/crate_version
use crate_version!() instead of reading the env + rustfmt
2021-06-03 10:56:57 +02:00
Sylvestre Ledru
24032498ad
Merge pull request #2339 from sylvestre/gnu-compat
Improve the gnu compat and use it for "touch"
2021-06-03 10:53:47 +02:00
Sylvestre Ledru
963a0da0b4
Merge pull request #2288 from syukronrm/du-time
du: fix `--time` behavior
2021-06-03 07:56:41 +02:00
Syukron Rifail M
05aeaf3061 du: fix --time behavior 2021-06-03 08:18:23 +07:00
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