mirror of
https://github.com/openai/codex.git
synced 2026-12-03 00:41:03 +00:00
## Why Configuration, protocol, and prompt code use in-memory policies and previously pulled in the Starlark parser through `codex-execpolicy`. ## What changed Move policy construction, rule validation, and evaluation into `codex-execpolicy-rules` and use it directly from those crates. Keep Starlark policy loading and file updates in `codex-execpolicy`, which re-exports the shared rule types and wraps rule validation errors while preserving their source locations. GitOrigin-RevId: 5bc70d3cd387b43a3ad1fcc56af96ad169ac8b13
33 lines
941 B
Rust
33 lines
941 B
Rust
use std::path::Path;
|
|
|
|
#[cfg(windows)]
|
|
const WINDOWS_EXECUTABLE_SUFFIXES: [&str; 4] = [".exe", ".cmd", ".bat", ".com"];
|
|
|
|
/// Return the key shared by host executable declarations and command lookups.
|
|
/// Windows folds ASCII case and ignores a recognized executable suffix.
|
|
pub fn executable_lookup_key(raw: &str) -> String {
|
|
#[cfg(windows)]
|
|
{
|
|
let raw = raw.to_ascii_lowercase();
|
|
for suffix in WINDOWS_EXECUTABLE_SUFFIXES {
|
|
if raw.ends_with(suffix) {
|
|
let stripped_len = raw.len() - suffix.len();
|
|
return raw[..stripped_len].to_string();
|
|
}
|
|
}
|
|
raw
|
|
}
|
|
|
|
#[cfg(not(windows))]
|
|
{
|
|
raw.to_string()
|
|
}
|
|
}
|
|
|
|
/// Derive a lookup key from the filename when it is valid UTF-8.
|
|
pub fn executable_path_lookup_key(path: &Path) -> Option<String> {
|
|
path.file_name()
|
|
.and_then(|name| name.to_str())
|
|
.map(executable_lookup_key)
|
|
}
|