{"record":{"id":"a5d207b449c4605f","repo":"chenhg5/cc-connect","slug":"chmod-new-binary-w","errorCode":null,"errorMessage":"chmod new binary: %w","messagePattern":"chmod new binary: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/cc-connect/update.go","lineNumber":451,"sourceCode":"\t// On Windows, rename over a running exe is not possible directly.\n\t// Move old binary aside, then move new one in.\n\tbackup := target + \".old\"\n\tos.Remove(backup)\n\n\tif err := os.Rename(target, backup); err != nil {\n\t\treturn fmt.Errorf(\"backup old binary: %w\", err)\n\t}\n\n\tif err := copyFile(src, target); err != nil {\n\t\t// Attempt to restore\n\t\tif restoreErr := os.Rename(backup, target); restoreErr != nil {\n\t\t\tslog.Warn(\"update: failed to restore old binary after copy error\", \"error\", restoreErr)\n\t\t}\n\t\treturn fmt.Errorf(\"install new binary: %w\", err)\n\t}\n\n\tif err := os.Chmod(target, 0o755); err != nil {\n\t\treturn fmt.Errorf(\"chmod new binary: %w\", err)\n\t}\n\n\tos.Remove(backup)\n\treturn nil\n}\n\nfunc copyFile(src, dst string) error {\n\tin, err := os.Open(src)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer in.Close()\n\n\tout, err := os.Create(dst)\n\tif err != nil {\n\t\treturn err\n\t}\n\tdefer out.Close()","sourceCodeStart":433,"sourceCodeEnd":469,"githubUrl":"https://github.com/chenhg5/cc-connect/blob/4000b2338aa6e850c99df54f8b0ed6ed7460b401/cmd/cc-connect/update.go#L433-L469","documentation":"After successfully copying the new binary, replaceExecutable sets executable permissions with os.Chmod(target, 0o755). If the chmod call fails the update aborts with \"chmod new binary: %w\". The new binary content is in place but may not be executable, and the backup file is intentionally left on disk because os.Remove(backup) is only reached on success.","triggerScenarios":"`cc-connect update` via runUpdate; the copy of the new binary succeeded but os.Chmod(target, 0o755) returned an error — e.g. the filesystem doesn't support chmod (some network mounts, Windows FAT/NTFS via WSL), or the user lacks ownership of the newly created file.","commonSituations":"Updating a binary installed in a directory mounted with 'noexec' or via a share that doesn't support POSIX permissions; running under WSL against /mnt/c; the install directory owned by another user after a previous sudo install.","solutions":["Check the wrapped chmod error; if it's permission-denied, take ownership of the binary: sudo chown $(whoami) <target>.","If the filesystem doesn't support permission bits (WSL /mnt/c, FAT/exFAT), move the install location to a native Linux filesystem.","Manually chmod +x the target binary and verify it runs (cc-connect --version); if OK, remove the stale backup file.","Avoid install directories mounted with noexec; relocate the binary to e.g. /usr/local/bin or ~/.local/bin.","Re-run `cc-connect update` after fixing the environment to complete cleanup of the backup file."],"exampleFix":"// before: binary on a mount without POSIX perms\nBinaryPath = \"/mnt/c/tools/cc-connect\"\n\n// after: install to a Linux-native path\nBinaryPath = \"/usr/local/bin/cc-connect\"","handlingStrategy":"validation","validationCode":"st, err := os.Stat(target)\nif err != nil { return err }\nif st.Mode().Perm()&0o755 == 0 {\n    // filesystem may not support chmod; test with a temp file first\n    tmp := target + \".chmodtest\"\n    os.WriteFile(tmp, []byte(\"x\"), 0o644)\n    _, err = os.Stat(tmp)\n    os.Remove(tmp)\n    if err != nil { return fmt.Errorf(\"install dir unusable: %w\", err) }\n}","typeGuard":null,"tryCatchPattern":"if err := runUpdate(); err != nil {\n    if strings.Contains(err.Error(), \"chmod new binary\") {\n        slog.Warn(\"chmod failed; binary may lack +x\", \"err\", err)\n        _ = os.Chmod(target, 0o755) // manual recovery attempt\n    }\n}","preventionTips":["Install binaries on POSIX-permission-capable filesystems (not /mnt/c, FAT, exFAT)","Avoid noexec-mounted install directories","Keep consistent ownership of the install path across updates","After an update, verify `cc-connect --version` runs before assuming success"],"tags":["update","chmod","permissions"],"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-14T00:17:10.932Z"}