mirror of
https://github.com/openai/codex.git
synced 2026-11-28 07:32:19 +00:00
Extract Windows deny-read glob scan planning into protocol (#43903)
Move lexical scan-bound calculation into `codex_protocol::permissions` and expose `windows_deny_read_glob_scan` with its `WindowsDenyReadGlobScan` result. Have the Windows sandbox resolver use the shared helper, preserving literal scan roots, glob suffixes, and traversal depth limits without filesystem access in the planner. GitOrigin-RevId: 748a12b45f89c6e045e9123c055453ec39c202b1
This commit is contained in:
1 parent
6d377e96eb
commit
4fd2c460dd
3 files changed
+53
-48
No files matched your search
@@ -3,6 +3,7 @@ use codex_protocol::permissions::FileSystemPath;
|
||||
use codex_protocol::permissions::FileSystemSandboxEntry;
|
||||
use codex_protocol::permissions::FileSystemSandboxPolicy;
|
||||
use codex_protocol::permissions::ReadDenyMatcher;
|
||||
use codex_protocol::permissions::windows_deny_read_glob_scan;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use std::collections::HashSet;
|
||||
use std::path::PathBuf;
|
||||
@@ -211,39 +212,11 @@ fn glob_scan_plans(
|
||||
}
|
||||
|
||||
fn glob_scan_plan(pattern: &str, configured_max_depth: Option<usize>) -> GlobScanPlan {
|
||||
// Start scanning at the deepest literal directory prefix before the first
|
||||
// glob metacharacter. For example, `C:\repo\**\*.env` only scans `C:\repo`
|
||||
// instead of the current directory or drive root.
|
||||
let first_glob = pattern
|
||||
.char_indices()
|
||||
.find(|(_, ch)| matches!(ch, '*' | '?' | '['))
|
||||
.map(|(index, _)| index)
|
||||
.unwrap_or(pattern.len());
|
||||
let literal_prefix = &pattern[..first_glob];
|
||||
let Some(separator_index) = literal_prefix.rfind(['/', '\\']) else {
|
||||
return GlobScanPlan {
|
||||
root: PathBuf::from("."),
|
||||
max_depth: effective_glob_scan_max_depth(pattern, configured_max_depth),
|
||||
globs: vec![ripgrep_glob(pattern)],
|
||||
};
|
||||
};
|
||||
let pattern_suffix = &pattern[separator_index + 1..];
|
||||
let is_drive_root_separator = separator_index > 0
|
||||
&& literal_prefix
|
||||
.as_bytes()
|
||||
.get(separator_index - 1)
|
||||
.is_some_and(|ch| *ch == b':');
|
||||
if separator_index == 0 || is_drive_root_separator {
|
||||
return GlobScanPlan {
|
||||
root: PathBuf::from(&literal_prefix[..=separator_index]),
|
||||
max_depth: effective_glob_scan_max_depth(pattern_suffix, configured_max_depth),
|
||||
globs: vec![ripgrep_glob(pattern_suffix)],
|
||||
};
|
||||
}
|
||||
let scan = windows_deny_read_glob_scan(pattern, configured_max_depth);
|
||||
GlobScanPlan {
|
||||
root: PathBuf::from(literal_prefix[..separator_index].to_string()),
|
||||
max_depth: effective_glob_scan_max_depth(pattern_suffix, configured_max_depth),
|
||||
globs: vec![ripgrep_glob(pattern_suffix)],
|
||||
root: PathBuf::from(scan.root),
|
||||
max_depth: scan.max_depth,
|
||||
globs: vec![ripgrep_glob(scan.pattern_suffix)],
|
||||
}
|
||||
}
|
||||
|
||||
@@ -285,22 +258,6 @@ fn ripgrep_glob(pattern: &str) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
fn effective_glob_scan_max_depth(
|
||||
pattern_suffix: &str,
|
||||
configured_max_depth: Option<usize>,
|
||||
) -> Option<usize> {
|
||||
let components = pattern_suffix
|
||||
.split(['/', '\\'])
|
||||
.filter(|component| !component.is_empty())
|
||||
.collect::<Vec<_>>();
|
||||
if components.contains(&"**") {
|
||||
return configured_max_depth;
|
||||
}
|
||||
Some(configured_max_depth.map_or(components.len(), |max_depth| {
|
||||
max_depth.min(components.len())
|
||||
}))
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
#[path = "deny_read_resolver_access_tests.rs"]
|
||||
mod access_tests;
|
||||
|
||||
Reference in new issue
Block a user