mirror of
https://github.com/openai/codex.git
synced 2026-11-18 22:20:48 +00:00
Reclaim abandoned trusted Git repositories (#61180)
## Why Temporary trusted Git repositories can remain on disk when a process exits without running directory cleanup. ## What changed Use `MarketplaceStagingDir` for trusted Git repositories under Codex home's `.tmp/.staging` directory. Clean up abandoned staging directories before creating a repository, while ownership locks protect repositories still in use. Reject a symlinked `.staging` directory to keep `GIT_DIR` inside Codex home. ## Testing Update the cross-process staging test to create trusted Git repositories and verify that cleanup preserves live owners, reclaims a repository after its process exits, and leaves a concurrent checkout intact. GitOrigin-RevId: f45b60db82814b4bcc09365f68d808c73d2d5378
This commit is contained in:
@@ -1,7 +1,8 @@
|
||||
use crate::marketplace_staging::MarketplaceStagingDir;
|
||||
use crate::marketplace_staging::cleanup_marketplace_staging;
|
||||
use codex_utils_absolute_path::AbsolutePathBuf;
|
||||
use std::path::Path;
|
||||
use std::process::Command;
|
||||
use tempfile::TempDir;
|
||||
|
||||
// These variables can redirect Git to an untrusted repository or inject command-scoped settings.
|
||||
pub(crate) const REPOSITORY_LOCAL_GIT_ENVIRONMENT_VARIABLES: &[&str] = &[
|
||||
@@ -56,7 +57,7 @@ impl PluginGitMode {
|
||||
pub(crate) fn configure_trusted_git_repository(
|
||||
command: &mut Command,
|
||||
codex_home: &Path,
|
||||
) -> Result<TempDir, String> {
|
||||
) -> Result<MarketplaceStagingDir, String> {
|
||||
let canonical_home = AbsolutePathBuf::from_absolute_path(codex_home)
|
||||
.and_then(|path| path.canonicalize())
|
||||
.map_err(|err| format!("failed to resolve trusted Codex home: {err}"))?;
|
||||
@@ -70,12 +71,15 @@ pub(crate) fn configure_trusted_git_repository(
|
||||
return Err("trusted Git repository root escapes Codex home".to_string());
|
||||
}
|
||||
|
||||
let repository = tempfile::Builder::new()
|
||||
.prefix("git-")
|
||||
.tempdir_in(staging_root.as_path())
|
||||
// Keep the explicit GIT_DIR inside Codex home. The staging cleaner skips symlinks.
|
||||
if staging_root.join(".staging").as_path().is_symlink() {
|
||||
return Err("trusted Git staging directory is a symlink".to_string());
|
||||
}
|
||||
cleanup_marketplace_staging(staging_root.as_path());
|
||||
let repository = MarketplaceStagingDir::new(staging_root.as_path())
|
||||
.map_err(|err| format!("failed to create trusted Git repository: {err}"))?;
|
||||
for directory in ["objects", "refs"] {
|
||||
std::fs::create_dir(repository.path().join(directory))
|
||||
std::fs::create_dir_all(repository.path().join(directory))
|
||||
.map_err(|err| format!("failed to initialize trusted Git repository: {err}"))?;
|
||||
}
|
||||
std::fs::write(repository.path().join("HEAD"), "ref: refs/heads/main\n")
|
||||
|
||||
Reference in New Issue
Block a user