mirror of
https://github.com/uutils/coreutils.git
synced 2026-06-10 15:48:22 -07:00
pipes.rs: replace bool by Result<(),()>
This commit is contained in:
@@ -481,7 +481,7 @@ fn print_fast<R: FdReadable>(handle: &mut InputHandle<R>) -> CatResult<()> {
|
||||
let mut stdout = stdout;
|
||||
// Try to use the splice() system call for faster writing. If it works, we're done.
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
if !uucore::pipes::splice_unbounded_auto(&handle.reader, &mut stdout)?
|
||||
if uucore::pipes::splice_unbounded_auto(&handle.reader, &mut stdout)?.is_ok()
|
||||
&& !uucore::pipes::might_fuse(&handle.reader)
|
||||
{
|
||||
return Ok(());
|
||||
|
||||
@@ -596,7 +596,7 @@ fn print_target_section<
|
||||
}
|
||||
} else {
|
||||
#[cfg(any(target_os = "linux", target_os = "android"))]
|
||||
if uucore::pipes::splice_unbounded_auto(file, &mut stdout)? {
|
||||
if uucore::pipes::splice_unbounded_auto(file, &mut stdout)?.is_err() {
|
||||
io::copy(file, &mut stdout)?;
|
||||
}
|
||||
#[cfg(not(any(target_os = "linux", target_os = "android")))]
|
||||
|
||||
@@ -23,7 +23,7 @@ pub fn copy_stream(
|
||||
) -> crate::error::UResult<()> {
|
||||
// If we're on Linux or Android, try to use the splice() system call
|
||||
// for faster writing. If it works, we're done.
|
||||
if crate::pipes::splice_unbounded_auto(src, dest)? {
|
||||
if crate::pipes::splice_unbounded_auto(src, dest)?.is_err() {
|
||||
// If the splice() call failed, fall back on writing "without buffering", or order of output would be wrong
|
||||
// unrelated for cp /dev/stdin since cp does not have multiple input? <https://github.com/uutils/coreutils/issues/5186>
|
||||
// RawWriter also removes io::copy's specialization
|
||||
|
||||
@@ -142,16 +142,17 @@ pub fn splice_unbounded_broker(
|
||||
|
||||
/// try splice_unbounded 1st and splice_unbounded_broker if both of in/output are not pipe
|
||||
///
|
||||
/// return true if write fallback is needed
|
||||
/// (the fallback will be embedded to this function in the future)
|
||||
/// see splice_unbounded_broker to handle returned error
|
||||
#[inline]
|
||||
pub fn splice_unbounded_auto(source: &impl AsFd, dest: &mut impl AsFd) -> std::io::Result<bool> {
|
||||
// use splice to check that input or output is pipe which is efficient
|
||||
let fallback = match splice(&source, dest, MAX_ROOTLESS_PIPE_SIZE) {
|
||||
Ok(_) => splice_unbounded(source, dest).is_err(),
|
||||
_ => splice_unbounded_broker(source, dest)?.is_err(),
|
||||
};
|
||||
Ok(fallback)
|
||||
pub fn splice_unbounded_auto(
|
||||
source: &impl AsFd,
|
||||
dest: &mut impl AsFd,
|
||||
) -> std::io::Result<Result<(), ()>> {
|
||||
if splice_unbounded(source, dest).is_err() {
|
||||
// input or output is not pipe
|
||||
return splice_unbounded_broker(source, dest);
|
||||
}
|
||||
Ok(Ok(()))
|
||||
}
|
||||
|
||||
/// splice `n` bytes with read/write fallback
|
||||
|
||||
Reference in New Issue
Block a user