Skip to content

Commit deedaee

Browse files
oech3oech3
authored andcommitted
Merge branch 'main' into gtest-build-time
2 parents bd6cb9e + 15d22c2 commit deedaee

File tree

13 files changed

+151
-54
lines changed

13 files changed

+151
-54
lines changed

.github/workflows/GnuTests.yml

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,8 @@ jobs:
8080
run: |
8181
## Install dependencies
8282
sudo apt-get update
83-
sudo apt-get install -y autopoint gperf gdb python3-pyinotify valgrind libexpect-perl libacl1-dev libattr1-dev libcap-dev libselinux1-dev attr quilt
83+
## Check that build-gnu.sh works on the non SELinux system by installing libselinux only on lima
84+
sudo apt-get install -y autopoint gperf gdb python3-pyinotify valgrind libexpect-perl libacl1-dev libattr1-dev libcap-dev attr quilt
8485
- name: Add various locales
8586
shell: bash
8687
run: |
@@ -109,7 +110,7 @@ jobs:
109110
run: |
110111
## Build binaries
111112
cd 'uutils'
112-
bash util/build-gnu.sh --release-build
113+
env PROFILE=release-small bash util/build-gnu.sh
113114
114115
### Run tests as user
115116
- name: Run GNU tests
@@ -244,7 +245,7 @@ jobs:
244245
### Build
245246
- name: Build binaries
246247
run: |
247-
lima bash -c "cd ~/work/uutils/ && SELINUX_ENABLED=1 bash util/build-gnu.sh --release-build"
248+
lima bash -c "cd ~/work/uutils/ && SELINUX_ENABLED=1 PROFILE=release-small bash util/build-gnu.sh"
248249
249250
### Run tests as user
250251
- name: Generate SELinux tests list

.github/workflows/benchmarks.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ jobs:
3737
- { package: uu_numfmt }
3838
- { package: uu_rm }
3939
- { package: uu_seq }
40+
- { package: uu_shuf }
4041
- { package: uu_sort }
4142
- { package: uu_split }
4243
- { package: uu_tsort }

Cargo.lock

Lines changed: 9 additions & 13 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -349,7 +349,6 @@ notify = { version = "=8.2.0", features = ["macos_kqueue"] }
349349
num-bigint = "0.4.4"
350350
num-prime = "0.4.4"
351351
num-traits = "0.2.19"
352-
number_prefix = "0.4"
353352
onig = { version = "~6.5.1", default-features = false }
354353
parse_datetime = "0.13.0"
355354
phf = "0.13.1"
@@ -373,6 +372,7 @@ textwrap = { version = "0.16.1", features = ["terminal_size"] }
373372
thiserror = "2.0.3"
374373
time = { version = "0.3.36" }
375374
unicode-width = "0.2.0"
375+
unit-prefix = "0.5"
376376
utmp-classic = "0.1.6"
377377
uutils_term_grid = "0.7"
378378
walkdir = "2.5"

DEVELOPMENT.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,9 @@ To run uutils against the GNU test suite locally, run the following commands:
230230
```shell
231231
bash util/build-gnu.sh
232232
# Build uutils with release optimizations
233-
bash util/build-gnu.sh --release-build
233+
env PROFILE=release bash util/build-gnu.sh
234+
# Build uutils with SELinux
235+
env SELINUX_ENABLED=1 bash util/build-gnu.sh
234236
bash util/run-gnu-test.sh
235237
# To run a single test:
236238
bash util/run-gnu-test.sh tests/touch/not-owner.sh # for example

fuzz/Cargo.lock

Lines changed: 7 additions & 7 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/uu/cp/src/cp.rs

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1375,10 +1375,19 @@ pub fn copy(sources: &[PathBuf], target: &Path, options: &Options) -> CopyResult
13751375
{
13761376
// There is already a file and it isn't a symlink (managed in a different place)
13771377
if copied_destinations.contains(&dest) && options.backup != BackupMode::Numbered {
1378-
// If the target file was already created in this cp call, do not overwrite
1379-
return Err(CpError::Error(
1380-
translate!("cp-error-will-not-overwrite-just-created", "dest" => dest.quote(), "source" => source.quote()),
1381-
));
1378+
// If the target was already created in this cp call, check if it's a directory.
1379+
// Directories should be merged (GNU cp behavior), but files should not be overwritten.
1380+
let dest_is_dir = fs::metadata(&dest).is_ok_and(|m| m.is_dir());
1381+
let source_is_dir = fs::metadata(source).is_ok_and(|m| m.is_dir());
1382+
1383+
// Only prevent overwriting if both source and dest are files (not directories)
1384+
// Directories should be merged, which is handled by copy_directory
1385+
if !dest_is_dir || !source_is_dir {
1386+
// If the target file was already created in this cp call, do not overwrite
1387+
return Err(CpError::Error(
1388+
translate!("cp-error-will-not-overwrite-just-created", "dest" => dest.quote(), "source" => source.quote()),
1389+
));
1390+
}
13821391
}
13831392
}
13841393

src/uu/shuf/Cargo.toml

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,12 @@ fluent = { workspace = true }
2727
[[bin]]
2828
name = "shuf"
2929
path = "src/main.rs"
30+
31+
[[bench]]
32+
name = "shuf_bench"
33+
harness = false
34+
35+
[dev-dependencies]
36+
divan = { workspace = true }
37+
tempfile = { workspace = true }
38+
uucore = { workspace = true, features = ["benchmark"] }

src/uu/shuf/benches/shuf_bench.rs

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
// This file is part of the uutils coreutils package.
2+
//
3+
// For the full copyright and license information, please view the LICENSE
4+
// file that was distributed with this source code.
5+
6+
use divan::{Bencher, black_box};
7+
use uu_shuf::uumain;
8+
use uucore::benchmark::{run_util_function, setup_test_file, text_data};
9+
10+
/// Benchmark shuffling lines from a file
11+
/// Tests the default mode with a large number of lines
12+
#[divan::bench(args = [100_000])]
13+
fn shuf_lines(bencher: Bencher, num_lines: usize) {
14+
let data = text_data::generate_by_lines(num_lines, 80);
15+
let file_path = setup_test_file(&data);
16+
let file_path_str = file_path.to_str().unwrap();
17+
18+
bencher.bench(|| {
19+
black_box(run_util_function(uumain, &[file_path_str]));
20+
});
21+
}
22+
23+
/// Benchmark shuffling a numeric range with -i
24+
/// Tests the input-range mode which uses a different algorithm
25+
#[divan::bench(args = [1_000_000])]
26+
fn shuf_input_range(bencher: Bencher, range_size: usize) {
27+
let range_arg = format!("1-{range_size}");
28+
29+
bencher.bench(|| {
30+
black_box(run_util_function(uumain, &["-i", &range_arg]));
31+
});
32+
}
33+
34+
/// Benchmark shuffling with repeat (sampling with replacement)
35+
/// Tests the -r flag combined with -n to output a specific count
36+
#[divan::bench(args = [50_000])]
37+
fn shuf_repeat_sampling(bencher: Bencher, num_lines: usize) {
38+
let data = text_data::generate_by_lines(10_000, 80);
39+
let file_path = setup_test_file(&data);
40+
let file_path_str = file_path.to_str().unwrap();
41+
let count = format!("{num_lines}");
42+
43+
bencher.bench(|| {
44+
black_box(run_util_function(
45+
uumain,
46+
&["-r", "-n", &count, file_path_str],
47+
));
48+
});
49+
}
50+
51+
fn main() {
52+
divan::main();
53+
}

src/uucore/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ bstr = { workspace = true }
2626
chrono = { workspace = true, optional = true }
2727
clap = { workspace = true }
2828
uucore_procs = { workspace = true }
29-
number_prefix = { workspace = true }
29+
unit-prefix = { workspace = true }
3030
phf = { workspace = true }
3131
dns-lookup = { workspace = true, optional = true }
3232
dunce = { version = "1.0.4", optional = true }

0 commit comments

Comments
 (0)