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:
viyatb-oai authored and copyberry committed 2026-07-30 00:50:02 +00:00
1 parent 7b93b3bf9c
commit b1ccaa0e08
3 files changed
+159 -15

No files matched your search

@@ -25,10 +25,12 @@ pub(crate) fn read_json_file(path: &Path) -> io::Result<Option<JsonValue>> {
}
pub(super) fn is_missing_or_empty_text_file(path: &Path) -> io::Result<bool> {
if !path.exists() {
return Ok(true);
}
if !path.is_file() {
let metadata = match fs::symlink_metadata(path) {
Ok(metadata) => metadata,
Err(err) if err.kind() == io::ErrorKind::NotFound => return Ok(true),
Err(err) => return Err(err),
};
if !metadata.is_file() {
return Ok(false);
}