{"record":{"id":"19a55566b5d584a7","repo":"chenhg5/cc-connect","slug":"resolve-symlinks-w","errorCode":null,"errorMessage":"resolve symlinks: %w","messagePattern":"resolve symlinks: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/updater.go","lineNumber":252,"sourceCode":"\t\t\trc, err := f.Open()\n\t\t\tif err != nil {\n\t\t\t\treturn nil, err\n\t\t\t}\n\t\t\tdefer rc.Close()\n\t\t\treturn io.ReadAll(rc)\n\t\t}\n\t}\n\treturn nil, fmt.Errorf(\"cc-connect binary not found in zip archive\")\n}\n\nfunc replaceBinary(newBinary []byte) error {\n\texecPath, err := os.Executable()\n\tif err != nil {\n\t\treturn fmt.Errorf(\"get executable path: %w\", err)\n\t}\n\texecPath, err = filepath.EvalSymlinks(execPath)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"resolve symlinks: %w\", err)\n\t}\n\n\tdir := filepath.Dir(execPath)\n\ttmpFile, err := os.CreateTemp(dir, \"cc-connect-update-*\")\n\tif err != nil {\n\t\treturn fmt.Errorf(\"create temp file: %w\", err)\n\t}\n\ttmpPath := tmpFile.Name()\n\n\tif _, err := tmpFile.Write(newBinary); err != nil {\n\t\ttmpFile.Close()\n\t\tos.Remove(tmpPath)\n\t\treturn fmt.Errorf(\"write new binary: %w\", err)\n\t}\n\ttmpFile.Close()\n\n\tif err := os.Chmod(tmpPath, 0o755); err != nil {\n\t\tos.Remove(tmpPath)","sourceCodeStart":234,"sourceCodeEnd":270,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/updater.go#L234-L270","documentation":"After obtaining the executable path, replaceBinary calls filepath.EvalSymlinks to resolve indirection; failure is wrapped as \"resolve symlinks: %w\". The updater must write next to the real binary, so unresolved or broken symlinks abort the update.","triggerScenarios":"SelfUpdate -> replaceBinary: EvalSymlinks returned an error because a component of the executable's path no longer exists (the binary or a parent dir was replaced/removed after start), a symlink loop exists, or a path component lacks search permission.","commonSituations":"Binary installed via a symlink chain (e.g. /usr/local/bin/cc-connect -> /opt/app/current/cc-connect) where a deploy later broke or removed the link while the old process still runs;管理者 removed the versioned target directory; permission-restricted directories after a security hardening change.","solutions":["Inspect the symlink chain: `ls -l $(which cc-connect)` and `readlink -f` it; recreate or fix the broken link, then retry the update.","Restart the process from a valid path so EvalSymlinks succeeds (broken chain usually only affects the already-running instance).","Reinstall the binary directly at the real target location and update from there, bypassing the broken symlink.","Check directory permissions (execute bit on every path component) if the error is permission-related.","Avoid symlink loops; point the stable link to a concrete versioned directory that exists."],"exampleFix":"# before: dangling symlink\nlrwxr-xr-x cc-connect -> /opt/cc-connect/v0.8/cc-connect  # v0.8 deleted\n# after\nln -sfn /opt/cc-connect/v0.9/cc-connect /usr/local/bin/cc-connect","handlingStrategy":"validation","validationCode":"p, _ := os.Executable()\nreal, err := filepath.EvalSymlinks(p)\nif err != nil {\n    return fmt.Errorf(\"broken install path: %v\", err)\n}\nif _, err := os.Stat(real); err != nil {\n    return fmt.Errorf(\"symlink target missing: %v\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := selfUpdate(); err != nil {\n    if strings.Contains(err.Error(), \"resolve symlinks\") {\n        // repair symlink chain (readlink -f) then reinstall/restart\n    }\n}","preventionTips":["Verify `readlink -f $(which cc-connect)` resolves before updating","Recreate symlink chains atomically (ln -sfn) on deploy","Keep path components executable (searchable) by the run user"],"tags":["filesystem","symlink","self-update"],"backgroundTag":"file-not-found","analyzedSha":"4000b2338aa6e850c99df54f8b0ed6ed7460b401","analyzedAt":"2026-09-06T11:45:09.575Z","contentChangedAt":"2026-09-06T11:45:09.575Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}