use async_trait::async_trait;
use std::path::{Path, PathBuf};
use std::sync::Arc;
use super::{Grant, GrantError};
use crate::interface::tool::ToolContext;
use crate::paths::SensitivePaths;
use crate::permission::PermissionRule;
#[async_trait]
pub trait PathGuard: Send + Sync + std::fmt::Debug {
async fn restore_check(&self, ctx: &ToolContext, target: &Path) -> Result<bool, String>;
fn command_writes(&self, globs: &[String], root: &Path) -> (Arc<dyn WriteScope>, Vec<String>);
fn host_writes(&self, globs: &[String], cwd: &Path) -> Arc<dyn WriteScope>;
fn reaches_configuration(&self, path: &str, cwd: &Path, paths: &SensitivePaths) -> bool;
fn admits(&self, grant: &Grant) -> Result<(), GrantError>;
}
pub trait WriteScope: Send + Sync + std::fmt::Debug {
fn covers(&self, path: &str, cwd: &Path) -> bool;
fn grants(&self) -> Vec<PermissionRule>;
fn fixed_prefixes_within(&self, root: &Path) -> Vec<PathBuf>;
}
#[derive(Debug, Default)]
pub struct NoWrites;
impl WriteScope for NoWrites {
fn covers(&self, _: &str, _: &Path) -> bool {
false
}
fn grants(&self) -> Vec<PermissionRule> {
Vec::new()
}
fn fixed_prefixes_within(&self, _: &Path) -> Vec<PathBuf> {
Vec::new()
}
}