Compare commits

...

1 Commits

Author SHA1 Message Date
Jiang Bohan
b4bd494575 refactor(execenv): collapse codex plugin cache stale-link branches
Merge the two symlink removal branches in exposeSharedCodexPluginCache —
they shared the same os.Remove + recreate path with only the error label
differing. The branch is now keyed off Lstat's ModeSymlink bit, with
Readlink reused only to fast-path an already-correct link. Behaviour is
unchanged; just less duplicated code.
2026-04-26 10:59:36 +08:00

View File

@@ -131,18 +131,14 @@ func exposeSharedCodexPluginCache(codexHome, sharedHome string) error {
}
if fi, err := os.Lstat(dst); err == nil {
target, readlinkErr := os.Readlink(dst)
if readlinkErr == nil {
if target == src {
isLink := fi.Mode()&os.ModeSymlink != 0
if isLink {
if target, readlinkErr := os.Readlink(dst); readlinkErr == nil && target == src {
return nil
}
if err := os.Remove(dst); err != nil {
return fmt.Errorf("remove stale plugin cache link: %w", err)
}
} else if fi.Mode()&os.ModeSymlink != 0 {
if err := os.Remove(dst); err != nil {
return fmt.Errorf("remove stale plugin cache symlink: %w", err)
}
} else {
if err := os.RemoveAll(dst); err != nil {
return fmt.Errorf("remove stale plugin cache path: %w", err)
@@ -213,7 +209,6 @@ func ensureSymlink(src, dst string) error {
// codex_sandbox.go's ensureCodexSandboxConfig so they can be updated
// idempotently without touching user-managed keys.)
// copyFileIfExists copies src to dst. If src doesn't exist, it's a no-op.
// If dst already exists, it's not overwritten.
func copyFileIfExists(src, dst string) error {