mirror of
https://github.com/RGBCube/uutils-coreutils
synced 2025-07-28 11:37:44 +00:00
cp: implement --copy-contents option for fifos
Implement the `--copy-contents` option when the source is a FIFO, so that the contents of the FIFO are copied (when the bytes become available for reading) instead of the FIFO object itself. For example, $ mkfifo fifo $ cp --copy-contents fifo outfile & [1] 1614080 $ echo foo > fifo $ cat outfile foo [1]+ Done cp --copy-contents fifo outfile
This commit is contained in:
parent
742c06965b
commit
5b100fef62
4 changed files with 87 additions and 22 deletions
|
@ -1,4 +1,4 @@
|
|||
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs
|
||||
// spell-checker:ignore (flags) reflink (fs) tmpfs (linux) rlimit Rlim NOFILE clob btrfs ROOTDIR USERDIR procfs outfile
|
||||
|
||||
use crate::common::util::*;
|
||||
#[cfg(not(windows))]
|
||||
|
@ -2226,3 +2226,32 @@ fn test_copy_dir_preserve_permissions_inaccessible_file() {
|
|||
let metadata2 = at.metadata("d2");
|
||||
assert_metadata_eq!(metadata1, metadata2);
|
||||
}
|
||||
|
||||
/// Test for copying the contents of a FIFO as opposed to the FIFO object itself.
|
||||
#[cfg(unix)]
|
||||
#[test]
|
||||
fn test_copy_contents_fifo() {
|
||||
let scenario = TestScenario::new(util_name!());
|
||||
let at = &scenario.fixtures;
|
||||
|
||||
// Start the `cp` process, reading the contents of `fifo` and
|
||||
// writing to regular file `outfile`.
|
||||
at.mkfifo("fifo");
|
||||
let mut ucmd = scenario.ucmd();
|
||||
let child = ucmd
|
||||
.args(&["--copy-contents", "fifo", "outfile"])
|
||||
.run_no_wait();
|
||||
|
||||
// Write some bytes to the `fifo`. We expect these bytes to get
|
||||
// copied through to `outfile`.
|
||||
std::fs::write(at.plus("fifo"), "foo").unwrap();
|
||||
|
||||
// At this point the child process should have terminated
|
||||
// successfully with no output. The `outfile` should have the
|
||||
// contents of `fifo` copied into it.
|
||||
let output = child.wait_with_output().unwrap();
|
||||
assert!(output.status.success());
|
||||
assert!(output.stdout.is_empty());
|
||||
assert!(output.stderr.is_empty());
|
||||
assert_eq!(at.read("outfile"), "foo");
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue