pub struct WorkspaceGuard { /* private fields */ }Expand description
Workspace safety checks to prevent editing files outside the target workspace.
Implementations§
Source§impl WorkspaceGuard
impl WorkspaceGuard
Sourcepub fn new(workspace_root: impl AsRef<Path>) -> Result<Self, SafetyError>
pub fn new(workspace_root: impl AsRef<Path>) -> Result<Self, SafetyError>
Create a new workspace guard with the given root.
The workspace root will be canonicalized to handle symlinks correctly.
Sourcepub fn validate_path(
&self,
path: impl AsRef<Path>,
) -> Result<PathBuf, SafetyError>
pub fn validate_path( &self, path: impl AsRef<Path>, ) -> Result<PathBuf, SafetyError>
Check if a path is safe to edit.
Returns the canonicalized absolute path if safe.
Note: This performs canonicalization at validation time. For maximum TOCTOU safety, callers should hold an open fd or re-validate immediately before write operations in adversarial environments.
Sourcepub fn revalidate(&self, path: &Path) -> Result<PathBuf, SafetyError>
pub fn revalidate(&self, path: &Path) -> Result<PathBuf, SafetyError>
Re-validate a previously-validated canonical path.
Call this immediately before write to close the TOCTOU window: the path is re-canonicalized and re-checked against workspace and forbidden boundaries.
Sourcepub fn workspace_root(&self) -> &Path
pub fn workspace_root(&self) -> &Path
Get the workspace root.
Trait Implementations§
Source§impl Clone for WorkspaceGuard
impl Clone for WorkspaceGuard
Source§fn clone(&self) -> WorkspaceGuard
fn clone(&self) -> WorkspaceGuard
Returns a duplicate of the value. Read more
1.0.0 · Source§fn clone_from(&mut self, source: &Self)
fn clone_from(&mut self, source: &Self)
Performs copy-assignment from
source. Read moreAuto Trait Implementations§
impl Freeze for WorkspaceGuard
impl RefUnwindSafe for WorkspaceGuard
impl Send for WorkspaceGuard
impl Sync for WorkspaceGuard
impl Unpin for WorkspaceGuard
impl UnsafeUnpin for WorkspaceGuard
impl UnwindSafe for WorkspaceGuard
Blanket Implementations§
Source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
Source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
Mutably borrows from an owned value. Read more