Compare commits

...

1 Commits

Author SHA1 Message Date
David Wiesen
8679dff2ee Fix Windows sandbox junction cwd root 2026-05-07 16:05:57 -07:00
2 changed files with 27 additions and 11 deletions

View File

@@ -159,7 +159,7 @@ fn read_spawn_request(
}
/// Pick an effective CWD, using a junction if the ACL helper is active.
fn effective_cwd(req_cwd: &Path, log_dir: Option<&Path>) -> PathBuf {
fn effective_cwd(req_cwd: &Path, sandbox_home: &Path, log_dir: Option<&Path>) -> PathBuf {
let use_junction = match read_acl_mutex::read_acl_mutex_exists() {
Ok(exists) => exists,
Err(err) => {
@@ -177,7 +177,8 @@ fn effective_cwd(req_cwd: &Path, log_dir: Option<&Path>) -> PathBuf {
"junction: read ACL helper running; using junction CWD",
log_dir,
);
cwd_junction::create_cwd_junction(req_cwd, log_dir).unwrap_or_else(|| req_cwd.to_path_buf())
cwd_junction::create_cwd_junction(req_cwd, sandbox_home, log_dir)
.unwrap_or_else(|| req_cwd.to_path_buf())
} else {
req_cwd.to_path_buf()
}
@@ -240,7 +241,7 @@ fn spawn_ipc_process(
}
}
let effective_cwd = effective_cwd(&req.cwd, Some(log_dir.as_path()));
let effective_cwd = effective_cwd(&req.cwd, req.codex_home.as_path(), Some(log_dir.as_path()));
log_note(
&format!(
"runner: effective cwd={} (requested {})",

View File

@@ -16,16 +16,16 @@ fn junction_name_for_path(path: &Path) -> String {
format!("{:x}", hasher.finish())
}
fn junction_root_for_userprofile(userprofile: &str) -> PathBuf {
PathBuf::from(userprofile)
.join(".codex")
.join(".sandbox")
.join("cwd")
fn junction_root_for_sandbox_home(sandbox_home: &Path) -> PathBuf {
sandbox_home.join("cwd")
}
pub fn create_cwd_junction(requested_cwd: &Path, log_dir: Option<&Path>) -> Option<PathBuf> {
let userprofile = std::env::var("USERPROFILE").ok()?;
let junction_root = junction_root_for_userprofile(&userprofile);
pub fn create_cwd_junction(
requested_cwd: &Path,
sandbox_home: &Path,
log_dir: Option<&Path>,
) -> Option<PathBuf> {
let junction_root = junction_root_for_sandbox_home(sandbox_home);
if let Err(err) = std::fs::create_dir_all(&junction_root) {
log_note(
&format!(
@@ -140,3 +140,18 @@ pub fn create_cwd_junction(requested_cwd: &Path, log_dir: Option<&Path>) -> Opti
);
None
}
#[cfg(test)]
mod tests {
use super::junction_root_for_sandbox_home;
use std::path::Path;
#[test]
fn junction_root_uses_sandbox_home_instead_of_userprofile() {
let sandbox_home = Path::new(r"C:\Users\alice\.codex\.sandbox");
assert_eq!(
junction_root_for_sandbox_home(sandbox_home),
Path::new(r"C:\Users\alice\.codex\.sandbox\cwd")
);
}
}