diff options
author | Ryan Lahfa <tvl@lahfa.xyz> | 2024-01-08T23·16+0100 |
---|---|---|
committer | raitobezarius <tvl@lahfa.xyz> | 2024-04-01T12·30+0000 |
commit | cecb5e295a7ca1d1c8eea273afc9a03434b78cf8 (patch) | |
tree | dbd7fadcce84a1d9f58afec902a3de3fba93d9b3 /tvix/glue/src/tvix_store_io.rs | |
parent | 14fe65a50b7bc1e31083c916d254043b0639d5aa (diff) |
feat(tvix/eval): implement `builtins.path` r/7840
Now, it supports almost everything except `recursive = false;`, i.e. `flat`-ingestion because we have no knob exposed in the tvix store import side to do it. This has been tested to work. Change-Id: I2e9da10ceccdfbf45b43c532077ed45d6306aa98 Reviewed-on: https://cl.tvl.fyi/c/depot/+/10597 Tested-by: BuildkiteCI Autosubmit: raitobezarius <tvl@lahfa.xyz> Reviewed-by: flokli <flokli@flokli.de>
Diffstat (limited to 'tvix/glue/src/tvix_store_io.rs')
-rw-r--r-- | tvix/glue/src/tvix_store_io.rs | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/tvix/glue/src/tvix_store_io.rs b/tvix/glue/src/tvix_store_io.rs index bfdab0846165..7b675bfc7d88 100644 --- a/tvix/glue/src/tvix_store_io.rs +++ b/tvix/glue/src/tvix_store_io.rs @@ -21,6 +21,7 @@ use tokio::io::AsyncReadExt; use tracing::{error, instrument, warn, Level}; use tvix_build::buildservice::BuildService; use tvix_eval::{ErrorKind, EvalIO, FileType, StdIO}; +use tvix_store::utils::AsyncIoBridge; use walkdir::DirEntry; use tvix_castore::{ @@ -341,6 +342,26 @@ impl TvixStoreIO { Ok(output_path) } + /// Transforms a BLAKE-3 digest into a SHA256 digest + /// by re-hashing the whole file. + pub(crate) async fn blob_to_sha256_hash(&self, blob_digest: B3Digest) -> io::Result<[u8; 32]> { + let mut reader = self + .blob_service + .open_read(&blob_digest) + .await? + .ok_or_else(|| { + io::Error::new( + io::ErrorKind::NotFound, + format!("blob represented by digest: '{}' not found", blob_digest), + ) + })?; + // It is fine to use `AsyncIoBridge` here because hashing is not actually I/O. + let mut hasher = AsyncIoBridge(Sha256::new()); + + tokio::io::copy(&mut reader, &mut hasher).await?; + Ok(hasher.0.finalize().into()) + } + pub async fn store_path_exists<'a>(&'a self, store_path: StorePathRef<'a>) -> io::Result<bool> { Ok(self .path_info_service |