MCPcopy Create free account
hub / github.com/atomicdotdev/atomic / detect_sandbox

Function detect_sandbox

atomic-repository/src/repository/sandbox.rs:99–121  ·  view source on GitHub ↗

Walk up from `start` looking for a [`SANDBOX_POINTER`] file. If found, return `(working_root, canonical_root, view)`.

(start: &Path)

Source from the content-addressed store, hash-verified

97/// Walk up from `start` looking for a [`SANDBOX_POINTER`] file. If found,
98/// return `(working_root, canonical_root, view)`.
99pub(super) fn detect_sandbox(start: &Path) -> Option<(PathBuf, PathBuf, String)> {
100 let mut dir = if start.is_absolute() {
101 start.to_path_buf()
102 } else {
103 std::env::current_dir().ok()?.join(start)
104 };
105
106 loop {
107 let pointer = dir.join(SANDBOX_POINTER);
108 if pointer.is_file() {
109 let bytes = std::fs::read(&pointer).ok()?;
110 let parsed: SandboxPointer = serde_json::from_slice(&bytes).ok()?;
111 return Some((dir.clone(), parsed.canonical, parsed.view));
112 }
113 // Stop if we reach a real repository root — that's not a sandbox.
114 if dir.join(DOT_DIR).join("pristine.redb").is_file() {
115 return None;
116 }
117 if !dir.pop() {
118 return None;
119 }
120 }
121}
122
123impl Repository {
124 /// Open a repository for an agent sandbox.

Callers 4

openMethod · 0.85
open_existingMethod · 0.85
open_readonlyMethod · 0.85
canonical_dot_dirMethod · 0.85

Calls 2

is_fileMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected