pub struct Workspace { /* private fields */ }Expand description
Shared handle passed into every filesystem-touching tool.
Implementations§
Source§impl Workspace
impl Workspace
Sourcepub fn detect(override_root: Option<&Path>) -> Result<Self>
pub fn detect(override_root: Option<&Path>) -> Result<Self>
Build a restricted workspace. If override_root is Some, use
it; otherwise walk up from cwd looking for a .git directory,
and fall back to cwd when none is found.
Sourcepub fn unrestricted() -> Self
pub fn unrestricted() -> Self
Build an unrestricted workspace rooted at cwd. No path checks
are performed. Kept for backward compatibility with callers and
tests that predate workspace enforcement; new production code
should use Workspace::detect.
Sourcepub fn is_restricted(&self) -> bool
pub fn is_restricted(&self) -> bool
Whether this workspace enforces the root boundary.
Sourcepub fn resolve(&self, input: &str) -> Result<PathBuf>
pub fn resolve(&self, input: &str) -> Result<PathBuf>
Resolve a caller-provided path that is expected to already exist.
Returns the canonical absolute path. On a restricted workspace,
the result must live under root after symlink resolution.
Sourcepub fn resolve_for_create(&self, input: &str) -> Result<PathBuf>
pub fn resolve_for_create(&self, input: &str) -> Result<PathBuf>
Resolve a caller-provided path that does not need to exist yet
(e.g. a write target). The parent directory must exist or
be creatable inside the workspace. We canonicalize the nearest
existing ancestor and confirm it lives under root, then
re-attach the non-existent tail.