{"record":{"id":"81a02327de89690b","repo":"chenhg5/cc-connect","slug":"create-temp-file-w-81a023","errorCode":null,"errorMessage":"create temp file: %w","messagePattern":"create temp file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"core/updater.go","lineNumber":258,"sourceCode":"\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)\n\t\treturn fmt.Errorf(\"chmod: %w\", err)\n\t}\n\n\toldPath := execPath + \".old\"\n\tos.Remove(oldPath)\n","sourceCodeStart":240,"sourceCodeEnd":276,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/core/updater.go#L240-L276","documentation":"replaceBinary creates a temporary file (cc-connect-update-*) in the executable's directory via os.CreateTemp; failure is wrapped as \"create temp file: %w\". The updater writes in-place next to the binary so the final rename is atomic on the same filesystem.","triggerScenarios":"SelfUpdate -> replaceBinary: os.CreateTemp(dir) failed — directory not writable by the running user (installed root-owned in /usr/local/bin, running as non-root), directory read-only, disk full (no inode/space), or the directory vanished after EvalSymlinks.","commonSituations":"Daemon running as an unprivileged user but binary owned by root (most common); immutable bit set on install dir; container filesystem mounted read-only; full disk/inode exhaustion on the host volume.","solutions":["Re-run the update with sufficient privileges (e.g. sudo cc-connect update) or chown/chmod the install directory so the running user can write: sudo chown $(whoami) $(dirname $(readlink -f $(which cc-connect))).","Free disk space / inodes (df -h, df -i) if the volume is full.","Remount the filesystem read-write if it is mounted ro, or move the installation to a writable location.","Check for chattr +i (immutable) on the directory or binary and remove it.","If self-update to a system path is undesirable, install the binary in a user-writable prefix (e.g. ~/.local/bin) and update from there."],"exampleFix":"# before\n$ cc-connect update\n# create temp file: open /usr/local/bin/cc-connect-update-*: permission denied\n# after\n$ sudo chown -R $(whoami) /usr/local/bin && cc-connect update","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(realExecPath)\nif info, err := os.Stat(dir); err != nil || info.Mode()&0o200 == 0 {\n    return fmt.Errorf(\"install dir not writable: %s\", dir)\n}\nif err := syscall.Access(dir, unix.W_OK); err != nil {\n    return fmt.Errorf(\"no write permission in %s: %v\", dir, err)\n}","typeGuard":null,"tryCatchPattern":"if err := selfUpdate(); err != nil {\n    if strings.Contains(err.Error(), \"create temp file\") {\n        // rerun with sudo or chown the install dir\n    }\n}","preventionTips":["Install cc-connect in a user-writable prefix (e.g. ~/.local/bin) for self-update","Check df -h / df -i for space before updating","Avoid read-only container filesystems for the install dir"],"tags":["filesystem","permissions","self-update"],"backgroundTag":"file-write-permission-denied","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"}