From f73ab76fcedffa8b6892b95e90cbf77e55451b52 Mon Sep 17 00:00:00 2001 From: Florian Klink Date: Fri, 6 Jan 2023 14:02:50 +0100 Subject: feat(tvix/store): add NixPath::to_absolute_path 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 Tested-by: BuildkiteCI --- tvix/store/src/nixpath.rs | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'tvix/store') diff --git a/tvix/store/src/nixpath.rs b/tvix/store/src/nixpath.rs index e7329b527c..54b964e83f 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] -- cgit 1.4.1