-
-
Notifications
You must be signed in to change notification settings - Fork 1.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
cp: truncate destination when --reflink
is set
#3759
Conversation
cool, could you please add a test for this ? thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
need test :)
87914e5
to
1b8b21e
Compare
I am not completely happy with the testing (it looks clunky, needs root, and may leak mount points in case of test failures) but I don't see a better way to check this (I believe tmpfs don't handle reflink). |
1b8b21e
to
e6c5a05
Compare
tests/by-util/test_cp.rs
Outdated
fn test_cp_reflink_always_override() { | ||
let scene = TestScenario::new(util_name!()); | ||
|
||
// Test must be run as root (or with `sudo -E`) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can you do like in
coreutils/tests/by-util/test_chown.rs
Lines 432 to 442 in 40095e1
#[test] | |
fn test_chown_only_user_id_nonexistent_user() { | |
let ts = TestScenario::new(util_name!()); | |
let at = ts.fixtures.clone(); | |
at.touch("f"); | |
if let Ok(result) = run_ucmd_as_root(&ts, &["12345", "f"]) { | |
result.success().no_stdout().no_stderr(); | |
} else { | |
print!("Test skipped; requires root user"); | |
} | |
} |
thanks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I am not sure this allows me to do what I want. My understanding is that only the tested command (cp
) can be run as root with run_ucmd_as_root
, while we need only need root for mount
/umount
in this test. Nevertheless, I tried to take into account this idea to allow running the test as non root (running sudo
only for mount
and umount
)
This is needed in order to allow overriding an existing file. ``` $ truncate -s 512M /tmp/disk.img $ mkfs.btrfs /tmp/disk.img [...] $ mkdir /tmp/disk $ sudo mount /tmp/disk.img /tmp/disk $ sudo chown $(id -u):$(id -g) -R /tmp/disk $ for i in $(seq 0 8192); do echo -ne 'a' >>/tmp/disk/src1; done $ echo "success" >/tmp/disk/src2 $ $ # GNU ls supports overriding files created with `--reflink` $ cp --reflink=always /tmp/disk/src1 /tmp/disk/dst1 $ cp --reflink=always /tmp/disk/src2 /tmp/disk/dst1 $ cat /tmp/disk/dst1 success $ $ # Now testing with uutils $ cargo run cp --reflink=always /tmp/disk/src1 /tmp/disk/dst2 Finished dev [unoptimized + debuginfo] target(s) in 0.25s Running `target/debug/coreutils cp --reflink=always /tmp/disk/src1 /tmp/disk/dst2` $ cargo run cp --reflink=always /tmp/disk/src2 /tmp/disk/dst2 Finished dev [unoptimized + debuginfo] target(s) in 0.26s Running `target/debug/coreutils cp --reflink=always /tmp/disk/src2 /tmp/disk/dst2` cp: failed to clone "/tmp/disk/src2" from "/tmp/disk/dst2": Invalid argument (os error 22) $ cat /tmp/disk/dst2 [lots of 'a'] $ $ # With truncate(true) $ cargo run cp --reflink=always /tmp/disk/src1 /tmp/disk/dst3 Finished dev [unoptimized + debuginfo] target(s) in 7.98s Running `target/debug/coreutils cp --reflink=always /tmp/disk/src1 /tmp/disk/dst3` $ cargo run cp --reflink=always /tmp/disk/src2 /tmp/disk/dst3 Finished dev [unoptimized + debuginfo] target(s) in 0.27s Running `target/debug/coreutils cp --reflink=always /tmp/disk/src2 /tmp/disk/dst3` $ cat /tmp/disk/dst3 success ```
712ed75
to
df2c69a
Compare
c9239a4
to
e920875
Compare
This is needed in order to allow overriding an existing file. closes #3758