mirror of
https://github.com/openai/codex.git
synced 2026-11-06 20:20:34 +00:00
refactor: derive filesystem access mode ordering
This commit is contained in:
@@ -577,9 +577,9 @@
|
||||
"FileSystemAccessMode": {
|
||||
"description": "Access mode for a filesystem entry.\n\nWhen two equally specific entries target the same path, we compare these by conflict precedence rather than by capability breadth: `none` beats `write`, and `write` beats `read`.",
|
||||
"enum": [
|
||||
"none",
|
||||
"read",
|
||||
"write"
|
||||
"write",
|
||||
"none"
|
||||
],
|
||||
"type": "string"
|
||||
},
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use std::cmp::Ordering;
|
||||
use std::collections::HashSet;
|
||||
use std::ffi::OsStr;
|
||||
use std::io;
|
||||
@@ -40,24 +39,29 @@ impl NetworkSandboxPolicy {
|
||||
/// When two equally specific entries target the same path, we compare these by
|
||||
/// conflict precedence rather than by capability breadth: `none` beats
|
||||
/// `write`, and `write` beats `read`.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize, Display, JsonSchema, TS)]
|
||||
#[derive(
|
||||
Debug,
|
||||
Clone,
|
||||
Copy,
|
||||
PartialEq,
|
||||
Eq,
|
||||
PartialOrd,
|
||||
Ord,
|
||||
Serialize,
|
||||
Deserialize,
|
||||
Display,
|
||||
JsonSchema,
|
||||
TS,
|
||||
)]
|
||||
#[serde(rename_all = "lowercase")]
|
||||
#[strum(serialize_all = "lowercase")]
|
||||
pub enum FileSystemAccessMode {
|
||||
None,
|
||||
Read,
|
||||
Write,
|
||||
None,
|
||||
}
|
||||
|
||||
impl FileSystemAccessMode {
|
||||
fn precedence_rank(self) -> u8 {
|
||||
match self {
|
||||
FileSystemAccessMode::Read => 0,
|
||||
FileSystemAccessMode::Write => 1,
|
||||
FileSystemAccessMode::None => 2,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn can_read(self) -> bool {
|
||||
!matches!(self, FileSystemAccessMode::None)
|
||||
}
|
||||
@@ -67,18 +71,6 @@ impl FileSystemAccessMode {
|
||||
}
|
||||
}
|
||||
|
||||
impl PartialOrd for FileSystemAccessMode {
|
||||
fn partial_cmp(&self, other: &Self) -> Option<Ordering> {
|
||||
Some(self.cmp(other))
|
||||
}
|
||||
}
|
||||
|
||||
impl Ord for FileSystemAccessMode {
|
||||
fn cmp(&self, other: &Self) -> Ordering {
|
||||
self.precedence_rank().cmp(&other.precedence_rank())
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone, PartialEq, Eq, Serialize, Deserialize, JsonSchema, TS)]
|
||||
#[serde(tag = "kind", rename_all = "snake_case")]
|
||||
#[ts(tag = "kind")]
|
||||
|
||||
Reference in New Issue
Block a user