pub struct Workspace { /* private fields */ }Expand description
A root directory that confines every path argument a tool receives.
Paths are resolved relative to the root (absolute paths are accepted only
if they land inside it) by the same resolver as the scope guard
(aidaemon_policies::resolve_path): one component at a time, every
symlink followed (a broken one to its target) and .. applied to the
directory really reached, before the containment check. A path that does
not exist yet is allowed when it resolves inside the root, so tools can
create new files and directories.
A path check is not a boundary against a hostile filesystem: a hard link
inside the root to a file outside resolves inside, and a concurrent
process that swaps a directory for a symlink between the check and the
I/O is not seen. Use a crate::Sandbox when the workspace itself is
shared with untrusted processes.
Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn new(root: impl AsRef<Path>) -> Result<Self>
pub fn new(root: impl AsRef<Path>) -> Result<Self>
Open an existing directory as a workspace. The root is canonicalized.
Sourcepub fn resolve(&self, path: &str) -> Result<PathBuf, PathError>
pub fn resolve(&self, path: &str) -> Result<PathBuf, PathError>
Resolve a path argument to a canonical absolute path inside the root. The path need not exist, but it must resolve inside the root (after following every symlink, including a broken last one).
Sourcepub fn declare(&self, path: &str) -> String
pub fn declare(&self, path: &str) -> String
Like Workspace::resolve but falls back to the lexical join, for
declaring access manifests before the call is validated.