Skip to content

armgit / codex

Public Imported from GitHub
0

Lightweight coding agent that runs in your terminal

Rust

fix(windows-sandbox): remove request files after read (#9316)

Max Konge2bd9311c9bd
diff --git a/codex-rs/windows-sandbox-rs/src/command_runner_win.rs b/codex-rs/windows-sandbox-rs/src/command_runner_win.rs
index 1739399901..a016c00c75 100644
--- a/codex-rs/windows-sandbox-rs/src/command_runner_win.rs
+++ b/codex-rs/windows-sandbox-rs/src/command_runner_win.rs
@@ -16,6 +16,7 @@ use codex_windows_sandbox::SandboxPolicy;
use serde::Deserialize;
use std::collections::HashMap;
use std::ffi::c_void;
+use std::path::Path;
use std::path::PathBuf;
use windows_sys::Win32::Foundation::CloseHandle;
use windows_sys::Win32::Foundation::GetLastError;
@@ -78,13 +79,20 @@ unsafe fn create_job_kill_on_close() -> Result<HANDLE> {
Ok(h)
}
+fn read_request_file(req_path: &Path) -> Result<String> {
+ let content = std::fs::read_to_string(req_path)
+ .with_context(|| format!("read request file {}", req_path.display()));
+ let _ = std::fs::remove_file(req_path);
+ content
+}
+
pub fn main() -> Result<()> {
let mut input = String::new();
let mut args = std::env::args().skip(1);
if let Some(first) = args.next() {
if let Some(rest) = first.strip_prefix("--request-file=") {
let req_path = PathBuf::from(rest);
- input = std::fs::read_to_string(&req_path).context("read request file")?;
+ input = read_request_file(&req_path)?;
}
}
if input.is_empty() {
@@ -265,3 +273,21 @@ pub fn main() -> Result<()> {
}
std::process::exit(exit_code);
}
+
+#[cfg(test)]
+mod tests {
+ use super::read_request_file;
+ use pretty_assertions::assert_eq;
+ use std::fs;
+
+ #[test]
+ fn removes_request_file_after_read() {
+ let dir = tempfile::tempdir().expect("tempdir");
+ let req_path = dir.path().join("request.json");
+ fs::write(&req_path, "{\"ok\":true}").expect("write request");
+
+ let content = read_request_file(&req_path).expect("read request");
+ assert_eq!(content, "{\"ok\":true}");
+ assert!(!req_path.exists(), "request file should be removed");
+ }
+}