refactor(tvix/store): rename NixPath to StorePath
As discussed in #tvl, this is a more common term for it. Change-Id: I9b904222b8c076f82192c9b7f0b42be171614ab7 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7776 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
999afd4be2
commit
c89af03a03
9 changed files with 68 additions and 65 deletions
|
|
@ -5,7 +5,7 @@ use serde::{Deserialize, Serialize};
|
|||
use sha2::{Digest, Sha256};
|
||||
use std::{collections::BTreeMap, fmt, fmt::Write};
|
||||
use tvix_store::nixbase32::NIXBASE32;
|
||||
use tvix_store::nixpath::{NixPath, ParseNixPathError, STORE_DIR};
|
||||
use tvix_store::nixpath::{ParseStorePathError, StorePath, STORE_DIR};
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Derivation {
|
||||
|
|
@ -34,10 +34,10 @@ fn build_store_path(
|
|||
is_derivation: bool,
|
||||
path_hash: &[u8],
|
||||
name: &str,
|
||||
) -> Result<NixPath, ParseNixPathError> {
|
||||
) -> Result<StorePath, ParseStorePathError> {
|
||||
let compressed = nix_hash::compress_hash(path_hash, 20);
|
||||
if is_derivation {
|
||||
NixPath::from_string(
|
||||
StorePath::from_string(
|
||||
format!(
|
||||
"{}-{}{}",
|
||||
NIXBASE32.encode(&compressed),
|
||||
|
|
@ -47,7 +47,7 @@ fn build_store_path(
|
|||
.as_str(),
|
||||
)
|
||||
} else {
|
||||
NixPath::from_string(format!("{}-{}", NIXBASE32.encode(&compressed), name,).as_str())
|
||||
StorePath::from_string(format!("{}-{}", NIXBASE32.encode(&compressed), name,).as_str())
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -105,8 +105,8 @@ impl Derivation {
|
|||
/// - Write the .drv A-Term contents to a hash function
|
||||
/// - Take the digest, run hash.CompressHash(digest, 20) on it.
|
||||
/// - Encode it with nixbase32
|
||||
/// - Use it (and the name) to construct a NixPath.
|
||||
pub fn calculate_derivation_path(&self, name: &str) -> Result<NixPath, ParseNixPathError> {
|
||||
/// - Use it (and the name) to construct a [StorePath].
|
||||
pub fn calculate_derivation_path(&self, name: &str) -> Result<StorePath, ParseStorePathError> {
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
// collect the list of paths from input_sources and input_derivations
|
||||
|
|
@ -223,7 +223,7 @@ impl Derivation {
|
|||
&mut self,
|
||||
name: &str,
|
||||
drv_replacement_str: &str,
|
||||
) -> Result<(), ParseNixPathError> {
|
||||
) -> Result<(), ParseStorePathError> {
|
||||
let mut hasher = Sha256::new();
|
||||
|
||||
// Check if the Derivation is fixed output, because they cause
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
use tvix_store::nixpath::NixPath;
|
||||
use tvix_store::nixpath::StorePath;
|
||||
|
||||
#[derive(Clone, Debug, Eq, PartialEq, Serialize, Deserialize)]
|
||||
pub struct Output {
|
||||
|
|
@ -23,7 +23,7 @@ impl Output {
|
|||
}
|
||||
|
||||
pub fn validate(&self) -> anyhow::Result<()> {
|
||||
NixPath::from_absolute_path(&self.path)?;
|
||||
StorePath::from_absolute_path(&self.path)?;
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use std::io::Read;
|
|||
use std::path::Path;
|
||||
use test_case::test_case;
|
||||
use test_generator::test_resources;
|
||||
use tvix_store::nixpath::NixPath;
|
||||
use tvix_store::nixpath::StorePath;
|
||||
|
||||
const RESOURCES_PATHS: &str = "src/tests/derivation_tests";
|
||||
|
||||
|
|
@ -66,7 +66,7 @@ fn derivation_path(name: &str, expected_path: &str) {
|
|||
|
||||
assert_eq!(
|
||||
derivation.calculate_derivation_path(name).unwrap(),
|
||||
NixPath::from_string(expected_path).unwrap()
|
||||
StorePath::from_string(expected_path).unwrap()
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -309,7 +309,7 @@ fn output_path_construction() {
|
|||
assert_eq!(foo_drv_expected, foo_drv);
|
||||
|
||||
assert_eq!(
|
||||
NixPath::from_string("4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv").expect("must succeed"),
|
||||
StorePath::from_string("4wvvbi4jwn0prsdxb7vs673qa5h9gr7x-foo.drv").expect("must succeed"),
|
||||
foo_drv
|
||||
.calculate_derivation_path("foo")
|
||||
.expect("must succeed")
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::{derivation::Derivation, write::DOT_FILE_EXT};
|
||||
use anyhow::bail;
|
||||
use tvix_store::nixpath::NixPath;
|
||||
use tvix_store::nixpath::StorePath;
|
||||
|
||||
impl Derivation {
|
||||
/// validate ensures a Derivation struct is properly populated,
|
||||
|
|
@ -35,7 +35,7 @@ impl Derivation {
|
|||
// Validate all input_derivations
|
||||
for (input_derivation_path, output_names) in &self.input_derivations {
|
||||
// Validate input_derivation_path
|
||||
NixPath::from_absolute_path(input_derivation_path)?;
|
||||
StorePath::from_absolute_path(input_derivation_path)?;
|
||||
if !input_derivation_path.ends_with(DOT_FILE_EXT) {
|
||||
bail!(
|
||||
"derivation {} does not end with .drv",
|
||||
|
|
@ -70,7 +70,7 @@ impl Derivation {
|
|||
|
||||
// Validate all input_sources
|
||||
for (i, input_source) in self.input_sources.iter().enumerate() {
|
||||
NixPath::from_absolute_path(input_source)?;
|
||||
StorePath::from_absolute_path(input_source)?;
|
||||
|
||||
if i > 0 && self.input_sources[i - 1] >= *input_source {
|
||||
bail!(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue