Skip to main content

outpost_core/ops/
lock.rs

1use std::path::PathBuf;
2
3use crate::{safety, OutpostError, OutpostResult, SourceRepo};
4
5pub struct LockOptions {
6    pub path: PathBuf,
7    pub reason: Option<String>,
8}
9
10pub fn run(source: &SourceRepo, opts: LockOptions) -> OutpostResult<()> {
11    let mut registry = source.registry_mut()?;
12    let path = registered_path(registry.entries(), &opts.path)?;
13    safety::check_path_is_managed_outpost_of(source, &path)?;
14    registry.lock(&path, opts.reason)?;
15    registry.save()
16}
17
18fn registered_path(
19    entries: &[crate::RegistryEntry],
20    path: &std::path::Path,
21) -> OutpostResult<PathBuf> {
22    let canonical = std::fs::canonicalize(path)
23        .map_err(|_| OutpostError::RegistryEntryNotFound(path.to_path_buf()))?;
24    if entries.iter().any(|entry| entry.path == canonical) {
25        Ok(canonical)
26    } else {
27        Err(OutpostError::RegistryEntryNotFound(canonical))
28    }
29}