refactor(tvix/glue): take &CAHash, not CAHash
We use a bit less cloning that way. Change-Id: I28bf99577e4a481e35fbf99d0724adab5502a1bd Reviewed-on: https://cl.tvl.fyi/c/depot/+/11874 Reviewed-by: Connor Brewster <cbrewster@hey.com> Tested-by: BuildkiteCI Reviewed-by: Ilan Joselevich <personal@ilanjoselevich.com>
This commit is contained in:
parent
78eb22c54d
commit
540e566900
3 changed files with 16 additions and 14 deletions
|
@ -284,27 +284,29 @@ mod import_builtins {
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
let obtained_hash = ca_hash.hash().clone().into_owned();
|
|
||||||
let (path_info, _hash, output_path) = state.tokio_handle.block_on(async {
|
let (path_info, _hash, output_path) = state.tokio_handle.block_on(async {
|
||||||
state
|
state
|
||||||
.node_to_path_info(name.as_ref(), path.as_ref(), ca_hash, root_node)
|
.node_to_path_info(name.as_ref(), path.as_ref(), &ca_hash, root_node)
|
||||||
.await
|
.await
|
||||||
})?;
|
})?;
|
||||||
|
|
||||||
if let Some(expected_sha256) = expected_sha256 {
|
if let Some(expected_sha256) = expected_sha256 {
|
||||||
if obtained_hash != expected_sha256 {
|
if *ca_hash.hash() != expected_sha256 {
|
||||||
Err(ImportError::HashMismatch(
|
Err(ImportError::HashMismatch(
|
||||||
path.to_string_lossy().to_string(),
|
path.to_string_lossy().to_string(),
|
||||||
expected_sha256,
|
expected_sha256,
|
||||||
obtained_hash,
|
ca_hash.hash().into_owned(),
|
||||||
))?;
|
))?;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let _: tvix_store::proto::PathInfo = state.tokio_handle.block_on(async {
|
state
|
||||||
// This is necessary to cause the coercion of the error type.
|
.tokio_handle
|
||||||
Ok::<_, std::io::Error>(state.path_info_service.as_ref().put(path_info).await?)
|
.block_on(async { state.path_info_service.as_ref().put(path_info).await })
|
||||||
})?;
|
.map_err(|e| tvix_eval::ErrorKind::IO {
|
||||||
|
path: Some(path.to_path_buf()),
|
||||||
|
error: Rc::new(e.into()),
|
||||||
|
})?;
|
||||||
|
|
||||||
// We need to attach context to the final output path.
|
// We need to attach context to the final output path.
|
||||||
let outpath = output_path.to_absolute_path();
|
let outpath = output_path.to_absolute_path();
|
||||||
|
@ -339,7 +341,7 @@ mod import_builtins {
|
||||||
.register_node_in_path_info_service(
|
.register_node_in_path_info_service(
|
||||||
name,
|
name,
|
||||||
&p,
|
&p,
|
||||||
CAHash::Nar(NixHash::Sha256(nar_sha256)),
|
&CAHash::Nar(NixHash::Sha256(nar_sha256)),
|
||||||
root_node,
|
root_node,
|
||||||
)
|
)
|
||||||
.await
|
.await
|
||||||
|
|
|
@ -357,7 +357,7 @@ impl TvixStoreIO {
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
ca: CAHash,
|
ca: &CAHash,
|
||||||
root_node: Node,
|
root_node: Node,
|
||||||
) -> io::Result<(PathInfo, NixHash, StorePath)> {
|
) -> io::Result<(PathInfo, NixHash, StorePath)> {
|
||||||
// Ask the PathInfoService for the NAR size and sha256
|
// Ask the PathInfoService for the NAR size and sha256
|
||||||
|
@ -372,7 +372,7 @@ impl TvixStoreIO {
|
||||||
|
|
||||||
// Calculate the output path. This might still fail, as some names are illegal.
|
// Calculate the output path. This might still fail, as some names are illegal.
|
||||||
let output_path =
|
let output_path =
|
||||||
nix_compat::store_path::build_ca_path(name, &ca, Vec::<String>::new(), false).map_err(
|
nix_compat::store_path::build_ca_path(name, ca, Vec::<String>::new(), false).map_err(
|
||||||
|_| {
|
|_| {
|
||||||
std::io::Error::new(
|
std::io::Error::new(
|
||||||
std::io::ErrorKind::InvalidData,
|
std::io::ErrorKind::InvalidData,
|
||||||
|
@ -399,7 +399,7 @@ impl TvixStoreIO {
|
||||||
&self,
|
&self,
|
||||||
name: &str,
|
name: &str,
|
||||||
path: &Path,
|
path: &Path,
|
||||||
ca: CAHash,
|
ca: &CAHash,
|
||||||
root_node: Node,
|
root_node: Node,
|
||||||
) -> io::Result<StorePath> {
|
) -> io::Result<StorePath> {
|
||||||
let (path_info, _, output_path) = self.node_to_path_info(name, path, ca, root_node).await?;
|
let (path_info, _, output_path) = self.node_to_path_info(name, path, ca, root_node).await?;
|
||||||
|
|
|
@ -81,7 +81,7 @@ pub fn path_to_name(path: &Path) -> std::io::Result<&str> {
|
||||||
pub fn derive_nar_ca_path_info(
|
pub fn derive_nar_ca_path_info(
|
||||||
nar_size: u64,
|
nar_size: u64,
|
||||||
nar_sha256: [u8; 32],
|
nar_sha256: [u8; 32],
|
||||||
ca: Option<CAHash>,
|
ca: Option<&CAHash>,
|
||||||
root_node: Node,
|
root_node: Node,
|
||||||
) -> PathInfo {
|
) -> PathInfo {
|
||||||
// assemble the [crate::proto::PathInfo] object.
|
// assemble the [crate::proto::PathInfo] object.
|
||||||
|
@ -145,7 +145,7 @@ where
|
||||||
let path_info = derive_nar_ca_path_info(
|
let path_info = derive_nar_ca_path_info(
|
||||||
nar_size,
|
nar_size,
|
||||||
nar_sha256,
|
nar_sha256,
|
||||||
Some(CAHash::Nar(NixHash::Sha256(nar_sha256))),
|
Some(&CAHash::Nar(NixHash::Sha256(nar_sha256))),
|
||||||
root_node,
|
root_node,
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue