From 05ef8a4b29b6a2deb2525989defd6c6714a13f5f Mon Sep 17 00:00:00 2001 From: Christian Schwarz Date: Fri, 12 Jan 2024 10:00:02 +0000 Subject: [PATCH] noop(VirtualFile): read_exact_at: actually vendor the rust std version Apart from sticking closer to the comment above the function, this reduces the diff in the next patch. --- pageserver/src/virtual_file.rs | 21 ++++++++++++--------- 1 file changed, 12 insertions(+), 9 deletions(-) diff --git a/pageserver/src/virtual_file.rs b/pageserver/src/virtual_file.rs index 061a305004..057805b3a9 100644 --- a/pageserver/src/virtual_file.rs +++ b/pageserver/src/virtual_file.rs @@ -509,24 +509,27 @@ impl VirtualFile { } // Copied from https://doc.rust-lang.org/1.72.0/src/std/os/unix/fs.rs.html#117-135 - pub async fn read_exact_at(&self, mut buf: &mut [u8], mut offset: u64) -> Result<(), Error> { + pub async fn read_exact_at(&self, mut buf: &mut [u8], mut offset: u64) -> std::io::Result<()> { while !buf.is_empty() { match self.read_at(buf, offset).await { - Ok(0) => { - return Err(Error::new( - std::io::ErrorKind::UnexpectedEof, - "failed to fill whole buffer", - )) - } + Ok(0) => break, Ok(n) => { - buf = &mut buf[n..]; + let tmp = buf; + buf = &mut tmp[n..]; offset += n as u64; } Err(ref e) if e.kind() == std::io::ErrorKind::Interrupted => {} Err(e) => return Err(e), } } - Ok(()) + if !buf.is_empty() { + Err(std::io::Error::new( + std::io::ErrorKind::UnexpectedEof, + "failed to fill whole buffer", + )) + } else { + Ok(()) + } } // Copied from https://doc.rust-lang.org/1.72.0/src/std/os/unix/fs.rs.html#219-235