mirror of
https://github.com/openai/codex.git
synced 2026-11-23 23:10:47 +00:00
## Why Pasted Windows drive paths were mapped unconditionally to `/mnt/<drive>`, even when that mount was unavailable or WSL used a different mapping. ## What changed Use `/bin/wslpath -u` with a one-second deadline and require an absolute result. Fall back to `/mnt/<drive>` only when the helper is missing and `/proc/self/mountinfo` confirms the mount exists. Reject fallback paths that traverse above the drive root and return no path when conversion fails. Share the bounded subprocess output helper with tmux probing. ## Testing Update coverage for quoted and unquoted Windows paths with spaces. Add fallback tests for a mounted drive, a missing drive mount, and traversal above the drive root. GitOrigin-RevId: f6a05045b2108722a686e9e5b766fc8cb233bea0
48 lines
1.4 KiB
Rust
48 lines
1.4 KiB
Rust
//! Capture short subprocess output without waiting on a pipe held open by descendants.
|
|
|
|
use std::io::Read;
|
|
use std::io::Seek;
|
|
use std::process::Command;
|
|
use std::time::Duration;
|
|
use std::time::Instant;
|
|
|
|
const POLL_INTERVAL: Duration = Duration::from_millis(/*millis*/ 10);
|
|
const MAX_OUTPUT_BYTES: u64 = 4096;
|
|
|
|
pub(crate) fn command_stdout_before_deadline(
|
|
command: &mut Command,
|
|
deadline: Instant,
|
|
) -> Option<Vec<u8>> {
|
|
if Instant::now() >= deadline {
|
|
return None;
|
|
}
|
|
let mut stdout = tempfile::tempfile().ok()?;
|
|
command.stdout(stdout.try_clone().ok()?);
|
|
let mut child = command.spawn().ok()?;
|
|
loop {
|
|
let remaining = deadline.saturating_duration_since(Instant::now());
|
|
match child.try_wait() {
|
|
Ok(Some(status)) => {
|
|
if !status.success() {
|
|
return None;
|
|
}
|
|
stdout.rewind().ok()?;
|
|
let mut output = Vec::new();
|
|
stdout
|
|
.take(MAX_OUTPUT_BYTES)
|
|
.read_to_end(&mut output)
|
|
.ok()?;
|
|
return Some(output);
|
|
}
|
|
Ok(None) if !remaining.is_zero() => {
|
|
std::thread::sleep(remaining.min(POLL_INTERVAL));
|
|
}
|
|
Ok(None) | Err(_) => {
|
|
let _ = child.kill();
|
|
let _ = child.wait();
|
|
return None;
|
|
}
|
|
}
|
|
}
|
|
}
|