Skip to main content

resolve_within_any

Function resolve_within_any 

Source
pub fn resolve_within_any(
    roots: &[(PathBuf, AccessTier)],
    path: &str,
    write: bool,
) -> Result<PathBuf>
Expand description

Multi-root variant of resolve_within. The candidate path is resolved against a set of allowed roots; it is accepted when its canonical form falls under at least one root. Symlink-aware canonicalisation is applied per-root exactly as in the single-root case.

write selects the tier check: a path that is only contained by ReadOnly roots is rejected for write operations (Write / Edit / StrReplace) with a clear error, while remaining readable.

This is the sandbox primitive used by every structured filesystem tool (Read / Write / Edit / Glob / Search / count_lines / estimate_tokens). It preserves invariant #3 — every fs path is still containment-checked — while letting the operator declare additional allowed roots beyond the primary workspace.