feat(nix-compat/narinfo): drop .drv from Narinfo.deriver field
We always know this needs to end with a .drv, and fail parsing if it doesn't, so there's no need to hang onto these 4 bytes. This will make it much easier to synthesize a NarInfo<'_> later on from a PathInfo proto, because we don't have to make this ".drv" appear out of thin air. Change-Id: Id95e7fd937d7c9a420a39b5a4bab73985640ca3b Reviewed-on: https://cl.tvl.fyi/c/depot/+/10084 Tested-by: BuildkiteCI Reviewed-by: edef <edef@edef.eu> Reviewed-by: raitobezarius <tvl@lahfa.xyz> Autosubmit: flokli <flokli@flokli.de>
This commit is contained in:
parent
ef8a8af0bf
commit
eb84898c17
2 changed files with 15 additions and 15 deletions
|
@ -53,7 +53,7 @@ pub struct NarInfo<'a> {
|
||||||
// derivation metadata
|
// derivation metadata
|
||||||
/// Nix system triple of [deriver]
|
/// Nix system triple of [deriver]
|
||||||
pub system: Option<&'a str>,
|
pub system: Option<&'a str>,
|
||||||
/// Store path of the derivation that produced this
|
/// Store path of the derivation that produced this. The last .drv suffix is stripped.
|
||||||
pub deriver: Option<StorePathRef<'a>>,
|
pub deriver: Option<StorePathRef<'a>>,
|
||||||
// cache-specific untrusted metadata
|
// cache-specific untrusted metadata
|
||||||
/// Relative URL of the compressed NAR file
|
/// Relative URL of the compressed NAR file
|
||||||
|
@ -227,16 +227,19 @@ impl<'a> NarInfo<'a> {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
"Deriver" => {
|
"Deriver" => {
|
||||||
let val = StorePathRef::from_bytes(val.as_bytes())
|
match val.strip_suffix(".drv") {
|
||||||
.map_err(Error::InvalidDeriverStorePath)?;
|
Some(val) => {
|
||||||
|
let val = StorePathRef::from_bytes(val.as_bytes())
|
||||||
|
.map_err(Error::InvalidDeriverStorePath)?;
|
||||||
|
|
||||||
if !val.name().ends_with(".drv") {
|
if deriver.replace(val).is_some() {
|
||||||
return Err(Error::InvalidDeriverStorePathMissingSuffix);
|
return Err(Error::DuplicateField(tag.to_string()));
|
||||||
}
|
}
|
||||||
|
}
|
||||||
if deriver.replace(val).is_some() {
|
None => {
|
||||||
return Err(Error::DuplicateField(tag.to_string()));
|
return Err(Error::InvalidDeriverStorePathMissingSuffix);
|
||||||
}
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
"Sig" => {
|
"Sig" => {
|
||||||
let val = Signature::parse(val)
|
let val = Signature::parse(val)
|
||||||
|
@ -325,7 +328,7 @@ impl Display for NarInfo<'_> {
|
||||||
writeln!(w)?;
|
writeln!(w)?;
|
||||||
|
|
||||||
if let Some(deriver) = &self.deriver {
|
if let Some(deriver) = &self.deriver {
|
||||||
writeln!(w, "Deriver: {deriver}")?;
|
writeln!(w, "Deriver: {deriver}.drv")?;
|
||||||
}
|
}
|
||||||
|
|
||||||
if let Some(system) = self.system {
|
if let Some(system) = self.system {
|
||||||
|
|
|
@ -212,10 +212,7 @@ impl From<&nix_compat::narinfo::NarInfo<'_>> for NarInfo {
|
||||||
signatures,
|
signatures,
|
||||||
reference_names: value.references.iter().map(|r| r.to_string()).collect(),
|
reference_names: value.references.iter().map(|r| r.to_string()).collect(),
|
||||||
deriver: value.deriver.as_ref().map(|sp| StorePath {
|
deriver: value.deriver.as_ref().map(|sp| StorePath {
|
||||||
// The parser already errors out with an error if the .drv suffix was missing,
|
name: sp.name().to_owned(),
|
||||||
// so you can only miss the suffix if you're manually constructing,
|
|
||||||
// which means we can unwrap here.
|
|
||||||
name: sp.name().strip_suffix(".drv").unwrap().to_owned(),
|
|
||||||
digest: Bytes::copy_from_slice(sp.digest()),
|
digest: Bytes::copy_from_slice(sp.digest()),
|
||||||
}),
|
}),
|
||||||
ca,
|
ca,
|
||||||
|
|
Loading…
Add table
Reference in a new issue