{"record":{"id":"822429007165647a","repo":"hasura/graphql-engine","slug":"rename-exe-to-old-w","errorCode":null,"errorMessage":"rename exe to old: %w","messagePattern":"rename exe to old: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/update/update.go","lineNumber":164,"sourceCode":"\t\treturn errors.E(op, fmt.Errorf(\"download asset: %w\", err))\n\t}\n\n\t// get the downloaded binary name and build the absolute path\n\tnewExe := asset.Name()\n\n\t// build name and absolute path for saving old binary\n\toldExeName := \".\" + exeName + \".old\"\n\toldExe := filepath.Join(exePath, oldExeName)\n\n\t// delete any existing old binary file - this is necessary on Windows for two reasons:\n\t// 1. after a successful update, Windows can't remove the .old file because the process is still running\n\t// 2. windows rename operations fail if the destination file already exists\n\t_ = os.Remove(oldExe)\n\n\t// rename the current binary as old binary\n\terr = os.Rename(exe, oldExe)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"rename exe to old: %w\", err))\n\t}\n\n\t// rename the new binary as the current binary\n\terr = os.Rename(newExe, exe)\n\tif err != nil {\n\t\t// rename unsuccessful\n\t\t//\n\t\t// The filesystem is now in a bad state. We have successfully\n\t\t// moved the existing binary to a new location, but we couldn't move the new\n\t\t// binary to take its place. That means there is no file where the current executable binary\n\t\t// used to be!\n\t\t// Try to rollback by restoring the old binary to its original path.\n\t\trerr := os.Rename(oldExe, exe)\n\t\tif rerr != nil {\n\t\t\t// rolling back failed, ask user to re-install cli\n\t\t\treturn errors.E(op, fmt.Errorf(\n\t\t\t\t\"rename old to exe: inconsistent state, re-install cli: %w\",\n\t\t\t\trerr))","sourceCodeStart":146,"sourceCodeEnd":182,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/update/update.go#L146-L182","documentation":"During ApplyUpdate's atomic swap, os.Rename(exe, oldExe) — renaming the current binary to '<exe>.old' — failed (cli/update/update.go:164). This happens before the new binary is moved into place, so the installation is still intact; typical causes are lacking write permission on the directory or the running executable being immutable/locked.","triggerScenarios":"ApplyUpdate where the install directory is not writable by the current user, another process holds a mandatory lock on the binary, or the filesystem does not allow renaming a running executable (some NFS/Windows configurations).","commonSituations":"CLI installed in /usr/local/bin and update run without sudo; Windows antivirus scanning the exe at the moment of rename; binary on a read-only or network mount.","solutions":["Ensure write permission on the directory containing the binary (or rerun the update with elevated privileges on macOS/Windows).","Delete a stale '<exe>.old' if it exists and the rename reports a conflict (preparation normally removes it, but check manually).","Disable/exclude the CLI binary from antivirus locking on Windows.","Avoid installing the binary on network filesystems where rename semantics are unreliable."],"exampleFix":"# before\n$ cli update\n# error: rename exe to old: permission denied\n\n# after (unix)\n$ sudo chown $(whoami) /usr/local/bin/cli\n$ cli update","handlingStrategy":"validation","validationCode":"dir := filepath.Dir(exe)\nif werr := testWritable(dir); werr != nil {\n    return fmt.Errorf(\"cannot update: %w (try adjusting permissions)\", werr)\n}","typeGuard":null,"tryCatchPattern":"if err := update.ApplyUpdate(v); err != nil {\n    if strings.Contains(err.Error(), \"rename exe to old\") {\n        // installation still intact, safe to keep using current version\n        log.Printf(\"update aborted before swap: %v\", err)\n    }\n    return err\n}","preventionTips":["Own the install directory (chown) or use a user-local install prefix.","Exclude the binary from antivirus real-time locks on Windows.","Remove stale .old files before updating."],"tags":["go","self-update","rename","permissions","filesystem"],"backgroundTag":"file-rename-permission-denied","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}