Skip to content

Commit d2c6d0b

Browse files
authored
Merge branch 'main' into gnu-cache
2 parents 102ffd6 + 415d01c commit d2c6d0b

File tree

4 files changed

+149
-51
lines changed

4 files changed

+149
-51
lines changed

src/uu/dd/src/progress.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ impl ProgUpdate {
147147
// Compute the throughput (bytes per second) as a string.
148148
let duration = self.duration.as_secs_f64();
149149
let safe_millis = std::cmp::max(1, self.duration.as_millis());
150-
let rate = 1000 * (btotal / safe_millis);
150+
let rate = (1000u128 * btotal) / safe_millis;
151151
let transfer_rate = to_magnitude_and_suffix(rate, SuffixType::Si);
152152

153153
// If we are rewriting the progress line, do write a carriage
@@ -644,15 +644,15 @@ mod tests {
644644
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
645645
assert_eq!(
646646
std::str::from_utf8(cursor.get_ref()).unwrap(),
647-
"1 byte copied, 1 s, 0.0 B/s\n"
647+
"1 byte copied, 1 s, 1.0 B/s\n"
648648
);
649649

650650
let prog_update = prog_update_write(999);
651651
let mut cursor = Cursor::new(vec![]);
652652
prog_update.write_prog_line(&mut cursor, rewrite).unwrap();
653653
assert_eq!(
654654
std::str::from_utf8(cursor.get_ref()).unwrap(),
655-
"999 bytes copied, 1 s, 0.0 B/s\n"
655+
"999 bytes copied, 1 s, 999 B/s\n"
656656
);
657657

658658
let prog_update = prog_update_write(1000);

tests/by-util/test_cp.rs

Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4101,6 +4101,110 @@ fn test_cp_dest_no_permissions() {
41014101
.stderr_contains("denied");
41024102
}
41034103

4104+
/// Test readonly destination behavior with reflink options
4105+
#[cfg(any(target_os = "linux", target_os = "macos"))]
4106+
#[test]
4107+
fn test_cp_readonly_dest_with_reflink() {
4108+
let ts = TestScenario::new(util_name!());
4109+
let at = &ts.fixtures;
4110+
4111+
at.write("source.txt", "source content");
4112+
at.write("readonly_dest_auto.txt", "original content");
4113+
at.write("readonly_dest_always.txt", "original content");
4114+
at.set_readonly("readonly_dest_auto.txt");
4115+
at.set_readonly("readonly_dest_always.txt");
4116+
4117+
// Test reflink=auto
4118+
ts.ucmd()
4119+
.args(&["--reflink=auto", "source.txt", "readonly_dest_auto.txt"])
4120+
.fails()
4121+
.stderr_contains("readonly_dest_auto.txt");
4122+
4123+
// Test reflink=always
4124+
ts.ucmd()
4125+
.args(&["--reflink=always", "source.txt", "readonly_dest_always.txt"])
4126+
.fails()
4127+
.stderr_contains("readonly_dest_always.txt");
4128+
4129+
assert_eq!(at.read("readonly_dest_auto.txt"), "original content");
4130+
assert_eq!(at.read("readonly_dest_always.txt"), "original content");
4131+
}
4132+
4133+
/// Test readonly destination behavior in recursive directory copy
4134+
#[test]
4135+
fn test_cp_readonly_dest_recursive() {
4136+
let ts = TestScenario::new(util_name!());
4137+
let at = &ts.fixtures;
4138+
4139+
at.mkdir("source_dir");
4140+
at.mkdir("dest_dir");
4141+
at.write("source_dir/file.txt", "source content");
4142+
at.write("dest_dir/file.txt", "original content");
4143+
at.set_readonly("dest_dir/file.txt");
4144+
4145+
ts.ucmd().args(&["-r", "source_dir", "dest_dir"]).succeeds();
4146+
4147+
assert_eq!(at.read("dest_dir/file.txt"), "original content");
4148+
}
4149+
4150+
/// Test copying to readonly file when another file exists
4151+
#[test]
4152+
fn test_cp_readonly_dest_with_existing_file() {
4153+
let ts = TestScenario::new(util_name!());
4154+
let at = &ts.fixtures;
4155+
4156+
at.write("source.txt", "source content");
4157+
at.write("readonly_dest.txt", "original content");
4158+
at.write("other_file.txt", "other content");
4159+
at.set_readonly("readonly_dest.txt");
4160+
4161+
ts.ucmd()
4162+
.args(&["source.txt", "readonly_dest.txt"])
4163+
.fails()
4164+
.stderr_contains("readonly_dest.txt")
4165+
.stderr_contains("denied");
4166+
4167+
assert_eq!(at.read("readonly_dest.txt"), "original content");
4168+
assert_eq!(at.read("other_file.txt"), "other content");
4169+
}
4170+
4171+
/// Test readonly source file (should work fine)
4172+
#[test]
4173+
fn test_cp_readonly_source() {
4174+
let ts = TestScenario::new(util_name!());
4175+
let at = &ts.fixtures;
4176+
4177+
at.write("readonly_source.txt", "source content");
4178+
at.write("dest.txt", "dest content");
4179+
at.set_readonly("readonly_source.txt");
4180+
4181+
ts.ucmd()
4182+
.args(&["readonly_source.txt", "dest.txt"])
4183+
.succeeds();
4184+
4185+
assert_eq!(at.read("dest.txt"), "source content");
4186+
}
4187+
4188+
/// Test readonly source and destination (should fail)
4189+
#[test]
4190+
fn test_cp_readonly_source_and_dest() {
4191+
let ts = TestScenario::new(util_name!());
4192+
let at = &ts.fixtures;
4193+
4194+
at.write("readonly_source.txt", "source content");
4195+
at.write("readonly_dest.txt", "original content");
4196+
at.set_readonly("readonly_source.txt");
4197+
at.set_readonly("readonly_dest.txt");
4198+
4199+
ts.ucmd()
4200+
.args(&["readonly_source.txt", "readonly_dest.txt"])
4201+
.fails()
4202+
.stderr_contains("readonly_dest.txt")
4203+
.stderr_contains("denied");
4204+
4205+
assert_eq!(at.read("readonly_dest.txt"), "original content");
4206+
}
4207+
41044208
#[test]
41054209
#[cfg(all(unix, not(target_os = "freebsd"), not(target_os = "openbsd")))]
41064210
fn test_cp_attributes_only() {

util/why-error.md

Lines changed: 42 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,42 @@
1-
This file documents why some tests are failing:
2-
* gnu/tests/cp/cp-a-selinux.sh
3-
* gnu/tests/cp/preserve-gid.sh
4-
* gnu/tests/date/date-debug.sh
5-
* gnu/tests/date/date.pl
6-
* gnu/tests/dd/no-allocate.sh
7-
* gnu/tests/dd/nocache_eof.sh
8-
* gnu/tests/dd/skip-seek-past-file.sh - https://github.com/uutils/coreutils/issues/7216
9-
* gnu/tests/dd/stderr.sh
10-
* gnu/tests/fmt/non-space.sh
11-
* gnu/tests/help/help-version-getopt.sh
12-
* gnu/tests/help/help-version.sh
13-
* gnu/tests/ls/ls-misc.pl
14-
* gnu/tests/ls/stat-free-symlinks.sh
15-
* gnu/tests/misc/close-stdout.sh
16-
* gnu/tests/misc/nohup.sh
17-
* gnu/tests/numfmt/numfmt.pl - https://github.com/uutils/coreutils/issues/7219 / https://github.com/uutils/coreutils/issues/7221
18-
* gnu/tests/misc/stdbuf.sh - https://github.com/uutils/coreutils/issues/7072
19-
* gnu/tests/misc/tsort.pl - https://github.com/uutils/coreutils/issues/7074
20-
* gnu/tests/misc/write-errors.sh
21-
* gnu/tests/od/od-float.sh
22-
* gnu/tests/ptx/ptx-overrun.sh
23-
* gnu/tests/ptx/ptx.pl
24-
* gnu/tests/rm/one-file-system.sh - https://github.com/uutils/coreutils/issues/7011
25-
* gnu/tests/rm/rm1.sh - https://github.com/uutils/coreutils/issues/9479
26-
* gnu/tests/shred/shred-passes.sh
27-
* gnu/tests/sort/sort-continue.sh
28-
* gnu/tests/sort/sort-debug-keys.sh
29-
* gnu/tests/sort/sort-debug-warn.sh
30-
* gnu/tests/sort/sort-float.sh
31-
* gnu/tests/sort/sort-h-thousands-sep.sh
32-
* gnu/tests/sort/sort-merge-fdlimit.sh
33-
* gnu/tests/sort/sort-month.sh
34-
* gnu/tests/sort/sort.pl
35-
* gnu/tests/tac/tac-2-nonseekable.sh
36-
* gnu/tests/tail/end-of-device.sh
37-
* gnu/tests/tail/follow-stdin.sh
38-
* gnu/tests/tail/inotify-rotate-resources.sh
39-
* gnu/tests/tail/symlink.sh
40-
* gnu/tests/tty/tty-eof.pl
1+
This file documents why some GNU tests are failing:
2+
* cp/cp-a-selinux.sh
3+
* cp/preserve-gid.sh
4+
* date/date-debug.sh
5+
* date/date.pl
6+
* dd/no-allocate.sh
7+
* dd/nocache_eof.sh
8+
* dd/skip-seek-past-file.sh - https://github.com/uutils/coreutils/issues/7216
9+
* dd/stderr.sh
10+
* fmt/non-space.sh
11+
* help/help-version-getopt.sh
12+
* help/help-version.sh
13+
* ls/ls-misc.pl
14+
* ls/stat-free-symlinks.sh
15+
* misc/close-stdout.sh
16+
* misc/nohup.sh
17+
* numfmt/numfmt.pl - https://github.com/uutils/coreutils/issues/7219 / https://github.com/uutils/coreutils/issues/7221
18+
* misc/stdbuf.sh - https://github.com/uutils/coreutils/issues/7072
19+
* misc/tsort.pl - https://github.com/uutils/coreutils/issues/7074
20+
* misc/write-errors.sh
21+
* od/od-float.sh
22+
* ptx/ptx-overrun.sh
23+
* ptx/ptx.pl
24+
* rm/one-file-system.sh - https://github.com/uutils/coreutils/issues/7011
25+
* rm/rm1.sh - https://github.com/uutils/coreutils/issues/9479
26+
* shred/shred-passes.sh
27+
* sort/sort-continue.sh
28+
* sort/sort-debug-keys.sh
29+
* sort/sort-debug-warn.sh
30+
* sort/sort-float.sh
31+
* sort/sort-h-thousands-sep.sh
32+
* sort/sort-merge-fdlimit.sh
33+
* sort/sort-month.sh
34+
* sort/sort.pl
35+
* tac/tac-2-nonseekable.sh
36+
* tail/end-of-device.sh
37+
* tail/follow-stdin.sh
38+
* tail/inotify-rotate-resources.sh
39+
* tail/symlink.sh
40+
* stty/stty-row-col.sh
41+
* stty/stty.sh
42+
* tty/tty-eof.pl

util/why-skip.md

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,6 @@
2020
= timeout returned 142. SIGALRM not handled? =
2121
* tests/misc/timeout-group.sh
2222

23-
= can't get window size =
24-
* tests/misc/stty-row-col.sh
25-
2623
= The Swedish locale with blank thousands separator is unavailable. =
2724
* tests/misc/sort-h-thousands-sep.sh
2825

@@ -32,11 +29,6 @@
3229
= no rootfs in mtab =
3330
* tests/df/skip-rootfs.sh
3431

35-
= requires controlling input terminal =
36-
* tests/misc/stty-pairs.sh
37-
* tests/misc/stty.sh
38-
* tests/misc/stty-invalid.sh
39-
4032
= Disabled. Enabled at GNU coreutils > 9.9 =
4133
* tests/misc/tac-continue.sh
4234
* tests/mkdir/writable-under-readonly.sh

0 commit comments

Comments
 (0)