From eb84898c177b5c4157efebc44c56459b9cf1ccf7 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Wed, 22 Nov 2023 20:11:22 +0200 Subject: 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 Reviewed-by: raitobezarius Autosubmit: flokli --- tvix/nix-compat/src/narinfo/mod.rs | 27 +++++++++++++++------------ 1 file changed, 15 insertions(+), 12 deletions(-) (limited to 'tvix/nix-compat') diff --git a/tvix/nix-compat/src/narinfo/mod.rs b/tvix/nix-compat/src/narinfo/mod.rs index 3fa73103bde6..8439403b59e9 100644 --- a/tvix/nix-compat/src/narinfo/mod.rs +++ b/tvix/nix-compat/src/narinfo/mod.rs @@ -53,7 +53,7 @@ pub struct NarInfo<'a> { // derivation metadata /// Nix system triple of [deriver] 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>, // cache-specific untrusted metadata /// Relative URL of the compressed NAR file @@ -227,16 +227,19 @@ impl<'a> NarInfo<'a> { } } "Deriver" => { - let val = StorePathRef::from_bytes(val.as_bytes()) - .map_err(Error::InvalidDeriverStorePath)?; - - if !val.name().ends_with(".drv") { - return Err(Error::InvalidDeriverStorePathMissingSuffix); - } - - if deriver.replace(val).is_some() { - return Err(Error::DuplicateField(tag.to_string())); - } + match val.strip_suffix(".drv") { + Some(val) => { + let val = StorePathRef::from_bytes(val.as_bytes()) + .map_err(Error::InvalidDeriverStorePath)?; + + if deriver.replace(val).is_some() { + return Err(Error::DuplicateField(tag.to_string())); + } + } + None => { + return Err(Error::InvalidDeriverStorePathMissingSuffix); + } + }; } "Sig" => { let val = Signature::parse(val) @@ -325,7 +328,7 @@ impl Display for NarInfo<'_> { writeln!(w)?; if let Some(deriver) = &self.deriver { - writeln!(w, "Deriver: {deriver}")?; + writeln!(w, "Deriver: {deriver}.drv")?; } if let Some(system) = self.system { -- cgit 1.4.1