diff options
author | Florian Klink <flokli@flokli.de> | 2023-01-06T13·02+0100 |
---|---|---|
committer | flokli <flokli@flokli.de> | 2023-01-06T15·39+0000 |
commit | f73ab76fcedffa8b6892b95e90cbf77e55451b52 (patch) | |
tree | 0ddbc9b2c907247f8537e7101d634245cb1de3cf /tvix/store | |
parent | 95bec264d55ddc4d1c9f53211c49899d93babd12 (diff) |
feat(tvix/store): add NixPath::to_absolute_path r/5611
This provides a function returning a string starting with the store path prefix, the counterpart of `from_absolute_path`. Change-Id: I4947f3b00171fe70357c62b3d64dc769b69e7a44 Reviewed-on: https://cl.tvl.fyi/c/depot/+/7774 Reviewed-by: tazjin <tazjin@tvl.su> Tested-by: BuildkiteCI
Diffstat (limited to 'tvix/store')
-rw-r--r-- | tvix/store/src/nixpath.rs | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/tvix/store/src/nixpath.rs b/tvix/store/src/nixpath.rs index e7329b527c5c..54b964e83f04 100644 --- a/tvix/store/src/nixpath.rs +++ b/tvix/store/src/nixpath.rs @@ -71,6 +71,12 @@ impl NixPath { } } + // Converts the NixPath to an absolute store path string. + /// That is a string starting with the store prefix (/nix/store) + pub fn to_absolute_path(&self) -> String { + format!("{}/{}", STORE_DIR, self) + } + fn validate_characters(s: &str) -> Result<(), ParseNixPathError> { for c in s.chars() { if c.is_ascii_alphanumeric() @@ -170,6 +176,11 @@ mod tests { .expect("must parse"); assert_eq!(nixpath_expected, nixpath_actual); + + assert_eq!( + "/nix/store/00bgd045z0d4icpbc2yyz4gx48ak44la-net-tools-1.60_p20170221182432", + nixpath_actual.to_absolute_path(), + ); } #[test] |