Skip to content

Commit 7020a11

Browse files
SUPERCILEXgitbot
authored and
gitbot
committed
Fix compilation issues on other unixes
Signed-off-by: Alex Saveau <saveau.alexandre@gmail.com>
1 parent 9b8b6af commit 7020a11

File tree

2 files changed

+53
-44
lines changed

2 files changed

+53
-44
lines changed

std/src/sys/pal/unix/fs.rs

+50-2
Original file line numberDiff line numberDiff line change
@@ -1984,14 +1984,62 @@ fn open_to_and_set_permissions(
19841984
Ok((writer, writer_metadata))
19851985
}
19861986

1987+
mod cfm {
1988+
use crate::fs::{File, Metadata};
1989+
use crate::io::{BorrowedCursor, IoSlice, IoSliceMut, Read, Result, Write};
1990+
1991+
#[allow(dead_code)]
1992+
pub struct CachedFileMetadata(pub File, pub Metadata);
1993+
1994+
impl Read for CachedFileMetadata {
1995+
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
1996+
self.0.read(buf)
1997+
}
1998+
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize> {
1999+
self.0.read_vectored(bufs)
2000+
}
2001+
fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> Result<()> {
2002+
self.0.read_buf(cursor)
2003+
}
2004+
#[inline]
2005+
fn is_read_vectored(&self) -> bool {
2006+
self.0.is_read_vectored()
2007+
}
2008+
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
2009+
self.0.read_to_end(buf)
2010+
}
2011+
fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
2012+
self.0.read_to_string(buf)
2013+
}
2014+
}
2015+
impl Write for CachedFileMetadata {
2016+
fn write(&mut self, buf: &[u8]) -> Result<usize> {
2017+
self.0.write(buf)
2018+
}
2019+
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize> {
2020+
self.0.write_vectored(bufs)
2021+
}
2022+
#[inline]
2023+
fn is_write_vectored(&self) -> bool {
2024+
self.0.is_write_vectored()
2025+
}
2026+
#[inline]
2027+
fn flush(&mut self) -> Result<()> {
2028+
self.0.flush()
2029+
}
2030+
}
2031+
}
2032+
#[cfg(any(target_os = "linux", target_os = "android"))]
2033+
pub(crate) use cfm::CachedFileMetadata;
2034+
19872035
#[cfg(not(target_vendor = "apple"))]
19882036
pub fn copy(from: &Path, to: &Path) -> io::Result<u64> {
19892037
let (reader, reader_metadata) = open_from(from)?;
19902038
let (writer, writer_metadata) = open_to_and_set_permissions(to, &reader_metadata)?;
19912039

19922040
io::copy(
1993-
&mut crate::sys::kernel_copy::CachedFileMetadata(reader, reader_metadata),
1994-
&mut crate::sys::kernel_copy::CachedFileMetadata(writer, writer_metadata),
2041+
&mut cfm::CachedFileMetadata(reader, reader_metadata),
2042+
&mut cfm::CachedFileMetadata(writer, writer_metadata),
19952043
)
19962044
}
19972045

std/src/sys/pal/unix/kernel_copy.rs

+3-42
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ use crate::cmp::min;
5252
use crate::fs::{File, Metadata};
5353
use crate::io::copy::generic_copy;
5454
use crate::io::{
55-
BorrowedCursor, BufRead, BufReader, BufWriter, Error, IoSlice, IoSliceMut, Read, Result,
56-
StderrLock, StdinLock, StdoutLock, Take, Write,
55+
BufRead, BufReader, BufWriter, Error, Read, Result, StderrLock, StdinLock, StdoutLock, Take,
56+
Write,
5757
};
5858
use crate::mem::ManuallyDrop;
5959
use crate::net::TcpStream;
@@ -65,6 +65,7 @@ use crate::process::{ChildStderr, ChildStdin, ChildStdout};
6565
use crate::ptr;
6666
use crate::sync::atomic::{AtomicBool, AtomicU8, Ordering};
6767
use crate::sys::cvt;
68+
use crate::sys::fs::CachedFileMetadata;
6869
use crate::sys::weak::syscall;
6970

7071
#[cfg(test)]
@@ -537,46 +538,6 @@ impl<T: ?Sized + CopyWrite> CopyWrite for BufWriter<T> {
537538
}
538539
}
539540

540-
pub(crate) struct CachedFileMetadata(pub File, pub Metadata);
541-
542-
impl Read for CachedFileMetadata {
543-
fn read(&mut self, buf: &mut [u8]) -> Result<usize> {
544-
self.0.read(buf)
545-
}
546-
fn read_vectored(&mut self, bufs: &mut [IoSliceMut<'_>]) -> Result<usize> {
547-
self.0.read_vectored(bufs)
548-
}
549-
fn read_buf(&mut self, cursor: BorrowedCursor<'_>) -> Result<()> {
550-
self.0.read_buf(cursor)
551-
}
552-
#[inline]
553-
fn is_read_vectored(&self) -> bool {
554-
self.0.is_read_vectored()
555-
}
556-
fn read_to_end(&mut self, buf: &mut Vec<u8>) -> Result<usize> {
557-
self.0.read_to_end(buf)
558-
}
559-
fn read_to_string(&mut self, buf: &mut String) -> Result<usize> {
560-
self.0.read_to_string(buf)
561-
}
562-
}
563-
impl Write for CachedFileMetadata {
564-
fn write(&mut self, buf: &[u8]) -> Result<usize> {
565-
self.0.write(buf)
566-
}
567-
fn write_vectored(&mut self, bufs: &[IoSlice<'_>]) -> Result<usize> {
568-
self.0.write_vectored(bufs)
569-
}
570-
#[inline]
571-
fn is_write_vectored(&self) -> bool {
572-
self.0.is_write_vectored()
573-
}
574-
#[inline]
575-
fn flush(&mut self) -> Result<()> {
576-
self.0.flush()
577-
}
578-
}
579-
580541
impl CopyRead for CachedFileMetadata {
581542
fn properties(&self) -> CopyParams {
582543
CopyParams(FdMeta::Metadata(self.1.clone()), Some(self.0.as_raw_fd()))

0 commit comments

Comments
 (0)