mirror of
https://github.com/openai/codex.git
synced 2026-11-22 23:00:42 +00:00
Avoid overwriting symlinked migration targets (#36051)
## Why External-agent migration treated symlinked empty text targets as overwritable files. Writing migrated configuration through such a target could modify a file outside the repository. ## What changed - Use symlink metadata when checking whether a migration target is missing or empty, so only regular files are considered overwritable. - Preserve symlinked `AGENTS.md` and `.codex/hooks.json` targets during both detection and import. ## Testing Added Unix regression coverage for existing and dangling symlink targets for both guidance and hooks migration. See https://github.com/openai/codex/pull/26021. GitOrigin-RevId: 13c78e7458d1c02abdb22b38ba88ed66bb5a154b
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
use crate::invalid_data_error;
|
||||
use crate::utils::is_missing_or_empty_text_file;
|
||||
use serde_json::Value as JsonValue;
|
||||
use std::fs;
|
||||
use std::io;
|
||||
@@ -271,17 +272,6 @@ pub(crate) fn json_u64(value: &JsonValue) -> Option<u64> {
|
||||
value.as_u64().or_else(|| value.as_str()?.parse().ok())
|
||||
}
|
||||
|
||||
fn is_missing_or_empty_text_file(path: &Path) -> io::Result<bool> {
|
||||
if !path.exists() {
|
||||
return Ok(true);
|
||||
}
|
||||
if !path.is_file() {
|
||||
return Ok(false);
|
||||
}
|
||||
|
||||
Ok(fs::read_to_string(path)?.trim().is_empty())
|
||||
}
|
||||
|
||||
pub(crate) fn external_agent_config_dir() -> String {
|
||||
format!(".{SOURCE_EXTERNAL_AGENT_NAME}")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user