Skip to main content

outpost_core/ops/
unlock.rs

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