init builtins
This commit is contained in:
@@ -69,13 +69,10 @@ impl Store for DaemonStore {
|
||||
fn ensure_path(&self, path: &str) -> Result<()> {
|
||||
self.block_on(async {
|
||||
self.connection.ensure_path(path).await.map_err(|e| {
|
||||
Error::eval_error(
|
||||
format!(
|
||||
"builtins.storePath: path '{}' is not valid in nix store: {}",
|
||||
path, e
|
||||
),
|
||||
None,
|
||||
)
|
||||
Error::eval_error(format!(
|
||||
"builtins.storePath: path '{}' is not valid in nix store: {}",
|
||||
path, e
|
||||
))
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
+34
-37
@@ -2,75 +2,72 @@ use crate::error::{Error, Result};
|
||||
|
||||
pub fn validate_store_path(store_dir: &str, path: &str) -> Result<()> {
|
||||
if !path.starts_with(store_dir) {
|
||||
return Err(Error::eval_error(
|
||||
format!("path '{}' is not in the Nix store", path),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"path '{}' is not in the Nix store",
|
||||
path
|
||||
)));
|
||||
}
|
||||
|
||||
let relative = path
|
||||
.strip_prefix(store_dir)
|
||||
.and_then(|s| s.strip_prefix('/'))
|
||||
.ok_or_else(|| Error::eval_error(format!("invalid store path format: {}", path), None))?;
|
||||
.ok_or_else(|| Error::eval_error(format!("invalid store path format: {}", path)))?;
|
||||
|
||||
if relative.is_empty() {
|
||||
return Err(Error::eval_error(
|
||||
format!("store path cannot be store directory itself: {}", path),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"store path cannot be store directory itself: {}",
|
||||
path
|
||||
)));
|
||||
}
|
||||
|
||||
let parts: Vec<&str> = relative.splitn(2, '-').collect();
|
||||
if parts.len() != 2 {
|
||||
return Err(Error::eval_error(
|
||||
format!("invalid store path format (missing name): {}", path),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"invalid store path format (missing name): {}",
|
||||
path
|
||||
)));
|
||||
}
|
||||
|
||||
let hash = parts[0];
|
||||
let name = parts[1];
|
||||
|
||||
if hash.len() != 32 {
|
||||
return Err(Error::eval_error(
|
||||
format!(
|
||||
"invalid store path hash length (expected 32, got {}): {}",
|
||||
hash.len(),
|
||||
hash
|
||||
),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"invalid store path hash length (expected 32, got {}): {}",
|
||||
hash.len(),
|
||||
hash
|
||||
)));
|
||||
}
|
||||
|
||||
for ch in hash.chars() {
|
||||
if !matches!(ch, '0'..='9' | 'a'..='d' | 'f'..='n' | 'p'..='s' | 'v'..='z') {
|
||||
return Err(Error::eval_error(
|
||||
format!("invalid character '{}' in store path hash: {}", ch, hash),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"invalid character '{}' in store path hash: {}",
|
||||
ch, hash
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
if name.is_empty() {
|
||||
return Err(Error::eval_error(
|
||||
format!("store path has empty name: {}", path),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"store path has empty name: {}",
|
||||
path
|
||||
)));
|
||||
}
|
||||
|
||||
if name.starts_with('.') {
|
||||
return Err(Error::eval_error(
|
||||
format!("store path name cannot start with '.': {}", name),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"store path name cannot start with '.': {}",
|
||||
name
|
||||
)));
|
||||
}
|
||||
|
||||
for ch in name.chars() {
|
||||
if !matches!(ch, '0'..='9' | 'a'..='z' | 'A'..='Z' | '+' | '-' | '.' | '_' | '?' | '=') {
|
||||
return Err(Error::eval_error(
|
||||
format!("invalid character '{}' in store path name: {}", ch, name),
|
||||
None,
|
||||
));
|
||||
return Err(Error::eval_error(format!(
|
||||
"invalid character '{}' in store path name: {}",
|
||||
ch, name
|
||||
)));
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user