From b4bd4945751df46d83d9b65b2885f09dcb9d962b Mon Sep 17 00:00:00 2001 From: Jiang Bohan Date: Sun, 26 Apr 2026 10:59:36 +0800 Subject: [PATCH] refactor(execenv): collapse codex plugin cache stale-link branches MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- server/internal/daemon/execenv/codex_home.go | 11 +++-------- 1 file changed, 3 insertions(+), 8 deletions(-) diff --git a/server/internal/daemon/execenv/codex_home.go b/server/internal/daemon/execenv/codex_home.go index 46b4a79c60..6df7591f76 100644 --- a/server/internal/daemon/execenv/codex_home.go +++ b/server/internal/daemon/execenv/codex_home.go @@ -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 {