refactor(tvix/nix-compat): move from_name_and_digest to StorePathRef
We can simply use .to_owned() on that thing afterwards if we want to construct an owned StorePath. Change-Id: I0f3e2e4434b99ee522f2a7dbfa391e13a987479c Reviewed-on: https://cl.tvl.fyi/c/depot/+/10105 Autosubmit: flokli <flokli@flokli.de> Reviewed-by: edef <edef@edef.eu> Tested-by: BuildkiteCI
This commit is contained in:
parent
eb84898c17
commit
671206a63f
2 changed files with 11 additions and 13 deletions
|
@ -107,14 +107,6 @@ impl StorePath {
|
|||
}
|
||||
}
|
||||
|
||||
/// Construct a [StorePath] from a name and digest.
|
||||
pub fn from_name_and_digest(name: String, digest: &[u8]) -> Result<StorePath, Error> {
|
||||
Ok(Self {
|
||||
name: validate_name(name.as_bytes())?.to_owned(),
|
||||
digest: digest.try_into().map_err(|_| Error::InvalidLength)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Decompose a string into a [StorePath] and a [PathBuf] containing the
|
||||
/// rest of the path, or an error.
|
||||
#[cfg(target_family = "unix")]
|
||||
|
@ -187,6 +179,14 @@ impl<'a> StorePathRef<'a> {
|
|||
}
|
||||
}
|
||||
|
||||
/// Construct a [StorePathRef] from a name and digest.
|
||||
pub fn from_name_and_digest(name: &'a str, digest: &[u8]) -> Result<Self, Error> {
|
||||
Ok(Self {
|
||||
name: validate_name(name.as_bytes())?,
|
||||
digest: digest.try_into().map_err(|_| Error::InvalidLength)?,
|
||||
})
|
||||
}
|
||||
|
||||
/// Construct a [StorePathRef] by passing the `$digest-$name` string
|
||||
/// that comes after [STORE_DIR_WITH_SLASH].
|
||||
pub fn from_bytes(s: &'a [u8]) -> Result<Self, Error> {
|
||||
|
|
|
@ -151,11 +151,9 @@ impl PathInfo {
|
|||
// 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)?;
|
||||
store_path::StorePathRef::from_name_and_digest(&deriver.name, &deriver.digest)
|
||||
.map_err(ValidatePathInfoError::InvalidDeriverField)?
|
||||
.to_owned();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue