diff options
author | Florian Klink <flokli@flokli.de> | 2023-05-22T11·42+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2023-05-23T10·48+0000 |
commit | 066179651c999e9680edae11817ca4ab42acc1ea (patch) | |
tree | dcc9badcaf27e0a0bc43842e8b3520e39080f351 /tvix/store/src/nar | |
parent | b8ff08b1b0d2dbd8dd546dc9cbdea2f11304d5c8 (diff) |
refactor(tvix/store/blobsvc): move from Vec<u8> to B3Digest r/6178
Change-Id: I809bab75221f81b6023cfe75c2fe9e589c1e9192 Reviewed-on: https://cl.tvl.fyi/c/depot/+/8605 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store/src/nar')
-rw-r--r-- | tvix/store/src/nar/renderer.rs | 33 |
1 files changed, 19 insertions, 14 deletions
diff --git a/tvix/store/src/nar/renderer.rs b/tvix/store/src/nar/renderer.rs index 9b71d24ac2a9..1804674fc44a 100644 --- a/tvix/store/src/nar/renderer.rs +++ b/tvix/store/src/nar/renderer.rs @@ -1,15 +1,13 @@ -use std::io::{self, BufReader}; - +use super::RenderError; use crate::{ blobservice::BlobService, directoryservice::DirectoryService, proto::{self, NamedNode}, B3Digest, }; -use data_encoding::BASE64; use nix_compat::nar; - -use super::RenderError; +use std::io::{self, BufReader}; +use tracing::warn; /// A NAR renderer, using a blob_service, chunk_service and directory_service /// to render a NAR to a writer. @@ -58,19 +56,26 @@ impl<BS: BlobService, DS: DirectoryService> NARRenderer<BS, DS> { .map_err(RenderError::NARWriterError)?; } proto::node::Node::File(proto_file_node) => { - let digest: [u8; 32] = - proto_file_node.digest.to_owned().try_into().map_err(|_e| { - RenderError::StoreError(crate::Error::StorageError( - "invalid digest len in file node".to_string(), - )) - })?; + let digest = B3Digest::from_vec(proto_file_node.digest.clone()).map_err(|_e| { + warn!( + file_node = ?proto_file_node, + "invalid digest length in file node", + ); + + RenderError::StoreError(crate::Error::StorageError( + "invalid digest len in file node".to_string(), + )) + })?; - // TODO: handle error - let mut blob_reader = match self.blob_service.open_read(&digest).unwrap() { + let mut blob_reader = match self + .blob_service + .open_read(&digest) + .map_err(|e| RenderError::StoreError(e))? + { Some(blob_reader) => Ok(BufReader::new(blob_reader)), None => Err(RenderError::NARWriterError(io::Error::new( io::ErrorKind::NotFound, - format!("blob with digest {} not found", BASE64.encode(&digest)), + format!("blob with digest {} not found", &digest), ))), }?; |