1
Fork 0
mirror of https://github.com/RGBCube/uutils-coreutils synced 2025-07-28 19:47:45 +00:00

sort: support percent arguments to -S option

Add support for parsing percent arguments to the `-S` option. The given
percentage specifies a percentage of the total physical memory. For
Linux, the total physical memory is read from `/proc/meminfo`. The
feature is not yet implemented for other systems.

In order to implement the feature, the `uucore::parser::parse_size`
function was updated to recognize strings of the form `NNN%`.

Fixes #3500
This commit is contained in:
Jeffrey Finkelstein 2025-01-20 12:36:10 -05:00
parent 39847a741a
commit 94c772c082
3 changed files with 97 additions and 2 deletions

View file

@ -29,6 +29,10 @@ fn test_helper(file_name: &str, possible_args: &[&str]) {
#[test]
fn test_buffer_sizes() {
#[cfg(target_os = "linux")]
let buffer_sizes = ["0", "50K", "50k", "1M", "100M", "0%", "10%"];
// TODO Percentage sizes are not yet supported beyond Linux.
#[cfg(not(target_os = "linux"))]
let buffer_sizes = ["0", "50K", "50k", "1M", "100M"];
for buffer_size in &buffer_sizes {
TestScenario::new(util_name!())
@ -73,6 +77,15 @@ fn test_invalid_buffer_size() {
.code_is(2)
.stderr_only("sort: invalid suffix in --buffer-size argument '100f'\n");
// TODO Percentage sizes are not yet supported beyond Linux.
#[cfg(target_os = "linux")]
new_ucmd!()
.arg("-S")
.arg("0x123%")
.fails()
.code_is(2)
.stderr_only("sort: invalid --buffer-size argument '0x123%'\n");
new_ucmd!()
.arg("-n")
.arg("-S")