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 <tazjin@tvl.su> Tested-by: BuildkiteCI
This commit is contained in:
parent
95bec264d5
commit
f73ab76fce
1 changed files with 11 additions and 0 deletions
|
@ -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]
|
||||
|
|
Loading…
Reference in a new issue