diff --git a/src/uu/dd/src/dd.rs b/src/uu/dd/src/dd.rs index 17368f9d256..1acdbd0dcc2 100644 --- a/src/uu/dd/src/dd.rs +++ b/src/uu/dd/src/dd.rs @@ -346,10 +346,16 @@ impl Dest { fn fsync(&mut self) -> io::Result<()> { match self { Self::Stdout(stdout) => stdout.flush(), - Self::File(f, _) | Self::Fifo(f) => { + Self::File(f, _) => { f.flush()?; f.sync_all() } + #[cfg(any(target_os = "linux", target_os = "android"))] + Self::Fifo(f) => { + f.flush()?; + f.sync_all() + } + #[cfg(any(target_os = "linux", target_os = "android"))] Self::Sink => Ok(()), } } @@ -357,10 +363,16 @@ impl Dest { fn fdatasync(&mut self) -> io::Result<()> { match self { Self::Stdout(stdout) => stdout.flush(), - Self::File(f, _) | Self::Fifo(f) => { + Self::File(f, _) => { + f.flush()?; + f.sync_data() + } + #[cfg(any(target_os = "linux", target_os = "android"))] + Self::Fifo(f) => { f.flush()?; f.sync_data() } + #[cfg(any(target_os = "linux", target_os = "android"))] Self::Sink => Ok(()), } } @@ -369,10 +381,12 @@ impl Dest { match self { Self::Stdout(stdout) => io::copy(&mut io::repeat(0).take(n), stdout), Self::File(f, _) => f.seek(io::SeekFrom::Start(n)), + #[cfg(any(target_os = "linux", target_os = "android"))] Self::Fifo(f) => { // Seeking in a named pipe means *reading* from the pipe. io::copy(&mut f.take(n), &mut io::sink()) } + #[cfg(any(target_os = "linux", target_os = "android"))] Self::Sink => Ok(0), } } @@ -394,8 +408,11 @@ impl Write for Dest { f.seek(io::SeekFrom::Current(seek_amt))?; Ok(buf.len()) } - Self::File(f, _) | Self::Fifo(f) => f.write(buf), + Self::File(f, _) => f.write(buf), Self::Stdout(stdout) => stdout.write(buf), + #[cfg(any(target_os = "linux", target_os = "android"))] + Self::Fifo(f) => f.write(buf), + #[cfg(any(target_os = "linux", target_os = "android"))] Self::Sink => Ok(buf.len()), } } @@ -403,7 +420,10 @@ impl Write for Dest { fn flush(&mut self) -> io::Result<()> { match self { Self::Stdout(stdout) => stdout.flush(), - Self::File(f, _) | Self::Fifo(f) => f.flush(), + Self::File(f, _) => f.flush(), + #[cfg(any(target_os = "linux", target_os = "android"))] + Self::Fifo(f) => f.flush(), + #[cfg(any(target_os = "linux", target_os = "android"))] Self::Sink => Ok(()), } }