Walk up from `start` looking for a [`SANDBOX_POINTER`] file. If found, return `(working_root, canonical_root, view)`.
(start: &Path)
| 97 | /// Walk up from `start` looking for a [`SANDBOX_POINTER`] file. If found, |
| 98 | /// return `(working_root, canonical_root, view)`. |
| 99 | pub(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 | |
| 123 | impl Repository { |
| 124 | /// Open a repository for an agent sandbox. |
no test coverage detected