refactor(nix-compat/store_path): add SP for build_nar_based_store_path
Make this generic on the StorePath<SP> that's being used, similar to the other functions in there. Change-Id: I453d1fd3749053d4e5aca156abc18da1f95ca264 Reviewed-on: https://cl.tvl.fyi/c/depot/+/12616 Tested-by: BuildkiteCI Autosubmit: flokli <flokli@flokli.de> Reviewed-by: Jörg Thalheim <joerg@thalheim.io> Reviewed-by: Ilan Joselevich <personal@ilanjoselevich.com>
This commit is contained in:
parent
3c3436d3ad
commit
da8fccba7a
1 changed files with 12 additions and 6 deletions
|
@ -1,6 +1,6 @@
|
||||||
use crate::nixbase32;
|
use crate::nixbase32;
|
||||||
use crate::nixhash::{CAHash, NixHash};
|
use crate::nixhash::{CAHash, NixHash};
|
||||||
use crate::store_path::{Error, StorePath, StorePathRef, STORE_DIR};
|
use crate::store_path::{Error, StorePath, STORE_DIR};
|
||||||
use data_encoding::HEXLOWER;
|
use data_encoding::HEXLOWER;
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
use thiserror;
|
use thiserror;
|
||||||
|
@ -119,12 +119,15 @@ where
|
||||||
.map_err(BuildStorePathError::InvalidStorePath)
|
.map_err(BuildStorePathError::InvalidStorePath)
|
||||||
}
|
}
|
||||||
|
|
||||||
/// For given NAR sha256 digest and name, return the new [StorePathRef] this
|
/// For given NAR sha256 digest and name, return the new [StorePath] this would
|
||||||
/// would have, or an error, in case the name is invalid.
|
/// have, or an error, in case the name is invalid.
|
||||||
pub fn build_nar_based_store_path<'a>(
|
pub fn build_nar_based_store_path<'a, SP>(
|
||||||
nar_sha256_digest: &[u8; 32],
|
nar_sha256_digest: &[u8; 32],
|
||||||
name: &'a str,
|
name: &'a str,
|
||||||
) -> Result<StorePathRef<'a>, BuildStorePathError> {
|
) -> Result<StorePath<SP>, BuildStorePathError>
|
||||||
|
where
|
||||||
|
SP: std::cmp::Eq + std::ops::Deref<Target = str> + std::convert::From<&'a str>,
|
||||||
|
{
|
||||||
let nar_hash_with_mode = CAHash::Nar(NixHash::Sha256(nar_sha256_digest.to_owned()));
|
let nar_hash_with_mode = CAHash::Nar(NixHash::Sha256(nar_sha256_digest.to_owned()));
|
||||||
|
|
||||||
build_ca_path(name, &nar_hash_with_mode, Vec::<String>::new(), false)
|
build_ca_path(name, &nar_hash_with_mode, Vec::<String>::new(), false)
|
||||||
|
@ -224,7 +227,10 @@ mod test {
|
||||||
use hex_literal::hex;
|
use hex_literal::hex;
|
||||||
|
|
||||||
use super::*;
|
use super::*;
|
||||||
use crate::nixhash::{CAHash, NixHash};
|
use crate::{
|
||||||
|
nixhash::{CAHash, NixHash},
|
||||||
|
store_path::StorePathRef,
|
||||||
|
};
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn build_text_path_with_zero_references() {
|
fn build_text_path_with_zero_references() {
|
||||||
|
|
Loading…
Reference in a new issue