diff options
author | Florian Klink <flokli@flokli.de> | 2024-08-20T13·52+0300 |
---|---|---|
committer | clbot <clbot@tvl.fyi> | 2024-08-20T15·14+0000 |
commit | 2beabe968ca70ce2aef8def08d7dab7340979ea6 (patch) | |
tree | 5d8521dc0228451960c6c77fd094e3a90a39fae6 /tvix/store/src/proto/mod.rs | |
parent | 413135b9252de65c61045ade984de7b4d3319c2d (diff) |
refactor(nix-compat/store_path): make StorePath generic on S r/8545
Similar to how cl/12253 already did this for `Signature`, we apply the same logic to `StorePath`. `StorePathRef<'a>'` is now a `StorePath<&'a str>`, and there's less redundant code for the two different implementation. `.as_ref()` returns a `StorePathRef<'_>`, `.to_owned()` gives a `StorePath<String>` (for now). I briefly thought about only publicly exporting `StorePath<String>` as `StorePath`, but the diff is not too large and this will make it easier to gradually introduce more flexibility in which store paths to accept. Also, remove some silliness in `StorePath::from_absolute_path_full`, which now doesn't allocate anymore. Change-Id: Ife8843857a1a0a3a99177ca997649fd45b8198e6 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12258 Autosubmit: flokli <flokli@flokli.de> Tested-by: BuildkiteCI Reviewed-by: Connor Brewster <cbrewster@hey.com>
Diffstat (limited to 'tvix/store/src/proto/mod.rs')
-rw-r--r-- | tvix/store/src/proto/mod.rs | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/tvix/store/src/proto/mod.rs b/tvix/store/src/proto/mod.rs index e6b411664037..f3ea4b196946 100644 --- a/tvix/store/src/proto/mod.rs +++ b/tvix/store/src/proto/mod.rs @@ -87,7 +87,7 @@ impl PathInfo { /// validate performs some checks on the PathInfo struct, /// Returning either a [store_path::StorePath] of the root node, or a /// [ValidatePathInfoError]. - pub fn validate(&self) -> Result<store_path::StorePath, ValidatePathInfoError> { + pub fn validate(&self) -> Result<store_path::StorePath<String>, ValidatePathInfoError> { // ensure the references have the right number of bytes. for (i, reference) in self.references.iter().enumerate() { if reference.len() != store_path::DIGEST_SIZE { @@ -118,7 +118,7 @@ impl PathInfo { // parse references in reference_names. for (i, reference_name_str) in narinfo.reference_names.iter().enumerate() { // ensure thy parse as (non-absolute) store path - let reference_names_store_path = store_path::StorePath::from_bytes( + let reference_names_store_path = store_path::StorePathRef::from_bytes( reference_name_str.as_bytes(), ) .map_err(|_| { @@ -160,6 +160,10 @@ impl PathInfo { let root_nix_path = match &self.node { None => Err(ValidatePathInfoError::NoNodePresent)?, Some(node) => { + // NOTE: We could have some PathComponent not allocating here, + // so this can return StorePathRef. + // However, as this will get refactored away to stricter types + // soon anyways, there's no point. let (name, _node) = node .clone() .into_name_and_node() @@ -356,7 +360,7 @@ impl From<&nix_compat::narinfo::NarInfo<'_>> for NarInfo { signatures, reference_names: value.references.iter().map(|r| r.to_string()).collect(), deriver: value.deriver.as_ref().map(|sp| StorePath { - name: sp.name().to_owned(), + name: (*sp.name()).to_owned(), digest: Bytes::copy_from_slice(sp.digest()), }), ca: value.ca.as_ref().map(|ca| ca.into()), |