From a3f486dc4b5b4aa8197be99ad8410b9c6f201d8d Mon Sep 17 00:00:00 2001 From: Colin Walters Date: Thu, 4 Sep 2025 14:03:16 -0400 Subject: [PATCH] get_raw_blob: Properly handle -1 return from GetRawBlob Just like GetBlob, the size might not be known. In the case of this API, one use case is being driven from e.g. https://github.com/cgwalters/cstor-dist which is exposing a HTTP API, so it's really useful for us to have the size here so that server can in turn provide it via its own `Content-Length` if available. Signed-off-by: Colin Walters --- src/imageproxy.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/imageproxy.rs b/src/imageproxy.rs index da30db5..8e5e791 100644 --- a/src/imageproxy.rs +++ b/src/imageproxy.rs @@ -686,20 +686,22 @@ impl ImageProxy { /// Fetch a blob identified by e.g. `sha256:`; does not perform /// any verification that the blob matches the digest. The size of the - /// blob and a pipe file descriptor are returned. + /// blob (if available) and a pipe file descriptor are returned. #[instrument] pub async fn get_raw_blob( &self, img: &OpenedImage, digest: &Digest, ) -> Result<( - u64, + Option, tokio::fs::File, impl Future> + Unpin + '_, )> { tracing::debug!("fetching blob"); let args: Vec = vec![img.0.into(), digest.to_string().into()]; - let (bloblen, fds): (u64, DualFds) = self.impl_request_with_fds("GetRawBlob", args).await?; + let (bloblen, fds): (i64, DualFds) = self.impl_request_with_fds("GetRawBlob", args).await?; + // See the GetBlob case, we have a best-effort attempt to return the size, but it might not be known + let bloblen = u64::try_from(bloblen).ok(); let fd = tokio::fs::File::from_std(std::fs::File::from(fds.datafd)); let err = Self::read_blob_error(fds.errfd).boxed(); Ok((bloblen, fd, err))