mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-27 19:17:43 +00:00
cp: clean existing file when copy from stream (#8149)
* cp: clean existing file when copy from stream * cp: remove outdated comments --------- Co-authored-by: Daniel Hofstetter <daniel.hofstetter@42dh.com>
This commit is contained in:
parent
f74cceabc7
commit
69bc6a791e
5 changed files with 94 additions and 42 deletions
|
@ -6247,6 +6247,55 @@ fn test_cp_update_none_interactive_prompt_no() {
|
|||
assert_eq!(at.read(new_file), "new content");
|
||||
}
|
||||
|
||||
/// only unix has `/dev/fd/0`
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn test_cp_from_stream() {
|
||||
let target = "target";
|
||||
let test_string1 = "longer: Hello, World!\n";
|
||||
let test_string2 = "shorter";
|
||||
let scenario = TestScenario::new(util_name!());
|
||||
let at = &scenario.fixtures;
|
||||
at.touch(target);
|
||||
|
||||
let mut ucmd = scenario.ucmd();
|
||||
ucmd.arg("/dev/fd/0")
|
||||
.arg(target)
|
||||
.pipe_in(test_string1)
|
||||
.succeeds();
|
||||
assert_eq!(at.read(target), test_string1);
|
||||
|
||||
let mut ucmd = scenario.ucmd();
|
||||
ucmd.arg("/dev/fd/0")
|
||||
.arg(target)
|
||||
.pipe_in(test_string2)
|
||||
.succeeds();
|
||||
assert_eq!(at.read(target), test_string2);
|
||||
}
|
||||
|
||||
/// only unix has `/dev/fd/0`
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn test_cp_from_stream_permission() {
|
||||
let target = "target";
|
||||
let link = "link";
|
||||
let test_string = "Hello, World!\n";
|
||||
let (at, mut ucmd) = at_and_ucmd!();
|
||||
|
||||
at.touch(target);
|
||||
at.symlink_file(target, link);
|
||||
let mode = 0o777;
|
||||
at.set_mode("target", mode);
|
||||
|
||||
ucmd.arg("/dev/fd/0")
|
||||
.arg(link)
|
||||
.pipe_in(test_string)
|
||||
.succeeds();
|
||||
|
||||
assert_eq!(at.read(target), test_string);
|
||||
assert_eq!(at.metadata(target).permissions().mode(), 0o100_777);
|
||||
}
|
||||
|
||||
#[cfg(feature = "feat_selinux")]
|
||||
fn get_getfattr_output(f: &str) -> String {
|
||||
use std::process::Command;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue