mirror of
https://github.com/multica-ai/multica.git
synced 2026-07-25 12:05:06 +02:00
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.
This commit is contained in:
@@ -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 {
|
||||
|
||||
Reference in New Issue
Block a user