refactor(nix-compat/store_path): don't materialise fingerprint
Change-Id: I6a88531ded05c0dfb9232a0343a465fa02fb6989 Reviewed-on: https://cl.tvl.fyi/c/depot/+/9856 Reviewed-by: flokli <flokli@flokli.de> Tested-by: BuildkiteCI
This commit is contained in:
parent
7f7c1ae7be
commit
6238a05868
1 changed files with 9 additions and 8 deletions
|
@ -2,6 +2,7 @@ use crate::nixbase32;
|
||||||
use crate::nixhash::{CAHash, NixHash};
|
use crate::nixhash::{CAHash, NixHash};
|
||||||
use crate::store_path::{Error, StorePath, STORE_DIR};
|
use crate::store_path::{Error, StorePath, STORE_DIR};
|
||||||
use sha2::{Digest, Sha256};
|
use sha2::{Digest, Sha256};
|
||||||
|
use std::io::Write;
|
||||||
use thiserror;
|
use thiserror;
|
||||||
|
|
||||||
/// Errors that can occur when creating a content-addressed store path.
|
/// Errors that can occur when creating a content-addressed store path.
|
||||||
|
@ -165,16 +166,16 @@ fn build_store_path_from_fingerprint_parts<B: AsRef<[u8]>>(
|
||||||
hash: &NixHash,
|
hash: &NixHash,
|
||||||
name: B,
|
name: B,
|
||||||
) -> Result<StorePath, Error> {
|
) -> Result<StorePath, Error> {
|
||||||
|
let name = name.as_ref();
|
||||||
let name = super::validate_name(name.as_ref())?;
|
let name = super::validate_name(name.as_ref())?;
|
||||||
let fingerprint =
|
|
||||||
String::from(ty) + ":" + &hash.to_nix_hash_string() + ":" + STORE_DIR + ":" + &name;
|
|
||||||
let digest = Sha256::new_with_prefix(fingerprint).finalize();
|
|
||||||
let compressed = compress_hash::<20>(&digest);
|
|
||||||
|
|
||||||
Ok(StorePath {
|
let digest = compress_hash(&{
|
||||||
digest: compressed,
|
let mut h = Sha256::new();
|
||||||
name,
|
write!(h, "{ty}:{}:{STORE_DIR}:{name}", hash.to_nix_hash_string()).unwrap();
|
||||||
})
|
h.finalize()
|
||||||
|
});
|
||||||
|
|
||||||
|
Ok(StorePath { digest, name })
|
||||||
}
|
}
|
||||||
|
|
||||||
/// This contains the Nix logic to create "text hash strings", which are used
|
/// This contains the Nix logic to create "text hash strings", which are used
|
||||||
|
|
Loading…
Reference in a new issue