refactor(tvix/store): move deriver field into narinfo submessage

This information is present in the .narinfo files, it should have gone
there.

Change-Id: Ib43d0cf30c2795bf1fe77c46646174353ade0458
Reviewed-on: https://cl.tvl.fyi/c/depot/+/9794
Autosubmit: flokli <flokli@flokli.de>
Reviewed-by: Connor Brewster <cbrewster@hey.com>
Tested-by: BuildkiteCI
This commit is contained in:
Florian Klink 2023-10-17 23:27:37 +01:00 committed by clbot
parent ba9a62ca9f
commit 9118dc8a50
11 changed files with 92 additions and 90 deletions

View file

@ -302,8 +302,8 @@ async fn main() -> Result<(), Box<dyn std::error::Error>> {
nar_sha256: nar_sha256.to_vec().into(),
signatures: vec![],
reference_names: vec![],
deriver: None,
}),
deriver: None,
};
// put into [PathInfoService], and return the PathInfo that we get back

View file

@ -140,6 +140,19 @@ impl PathInfo {
);
}
}
// If the Deriver field is populated, ensure it parses to a
// [store_path::StorePath].
// We can't check for it to *not* end with .drv, as the .drv files produced by
// recursive Nix end with multiple .drv suffixes, and only one is popped when
// converting to this field.
if let Some(deriver) = &narinfo.deriver {
store_path::StorePath::from_name_and_digest(
deriver.name.clone(),
&deriver.digest,
)
.map_err(ValidatePathInfoError::InvalidDeriverField)?;
}
}
}
@ -156,16 +169,6 @@ impl PathInfo {
}
};
// If the Deriver field is populated, ensure it parses to a
// [store_path::StorePath].
// We can't check for it to *not* end with .drv, as the .drv files produced by
// recursive Nix end with multiple .drv suffixes, and only one is popped when
// converting to this field.
if let Some(deriver) = &self.deriver {
store_path::StorePath::from_name_and_digest(deriver.name.clone(), &deriver.digest)
.map_err(ValidatePathInfoError::InvalidDeriverField)?;
}
// return the root nix path
Ok(root_nix_path)
}

View file

@ -266,10 +266,11 @@ fn validate_symlink_target_null_byte_invalid() {
/// Create a PathInfo with a correct deriver field and ensure it succeeds.
#[test]
fn validate_valid_deriver() {
let mut path_info = PATH_INFO_WITHOUT_NARINFO.clone();
let mut path_info = PATH_INFO_WITH_NARINFO.clone();
// add a valid deriver
path_info.deriver = Some(crate::proto::StorePath {
let narinfo = path_info.narinfo.as_mut().unwrap();
narinfo.deriver = Some(crate::proto::StorePath {
name: "foo".to_string(),
digest: DUMMY_OUTPUT_HASH.clone(),
});
@ -280,10 +281,11 @@ fn validate_valid_deriver() {
/// Create a PathInfo with a broken deriver field and ensure it fails.
#[test]
fn validate_invalid_deriver() {
let mut path_info = PATH_INFO_WITHOUT_NARINFO.clone();
let mut path_info = PATH_INFO_WITH_NARINFO.clone();
// add a broken deriver (invalid digest)
path_info.deriver = Some(crate::proto::StorePath {
let narinfo = path_info.narinfo.as_mut().unwrap();
narinfo.deriver = Some(crate::proto::StorePath {
name: "foo".to_string(),
digest: vec![].into(),
});

View file

@ -109,7 +109,6 @@ lazy_static! {
}),
references: vec![DUMMY_OUTPUT_HASH.clone()],
narinfo: None,
deriver: None,
};
/// A PathInfo message with .narinfo populated.
@ -121,6 +120,7 @@ lazy_static! {
nar_sha256: DUMMY_DIGEST.clone().into(),
signatures: vec![],
reference_names: vec![DUMMY_NAME.to_string()],
deriver: None,
}),
..PATH_INFO_WITHOUT_NARINFO.clone()
};