{"record":{"id":"fcd52bc2867c2a98","repo":"abiosoft/colima","slug":"error-backing-up-existing-file-w","errorCode":null,"errorMessage":"error backing up existing file: %w","messagePattern":"error backing up existing file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cmd/nerdctl.go","lineNumber":127,"sourceCode":"\n\t\t\tvar values = struct {\n\t\t\t\tColimaApp string\n\t\t\t\tProfile   string\n\t\t\t}{\n\t\t\t\tColimaApp: osutil.Executable(),\n\t\t\t\tProfile:   config.CurrentProfile().ShortName,\n\t\t\t}\n\t\t\tbuf, err := util.ParseTemplate(nerdctlScript, values)\n\t\t\tif err != nil {\n\t\t\t\treturn fmt.Errorf(\"error applying nerdctl script template: %w\", err)\n\t\t\t}\n\n\t\t\t// /usr/local/bin writeable i.e. sudo not needed\n\t\t\t// or user-specified install path, we assume user specified path is writeable\n\t\t\tif nerdctlCmdArgs.usrBinWriteable || nerdctlCmdArgs.path != nerdctlDefaultInstallPath {\n\t\t\t\tif exists {\n\t\t\t\t\tif err := os.Rename(nerdctlCmdArgs.path, nerdctlCmdArgs.path+\".moved\"); err != nil {\n\t\t\t\t\t\treturn fmt.Errorf(\"error backing up existing file: %w\", err)\n\t\t\t\t\t}\n\t\t\t\t}\n\t\t\t\tif err := fsutil.MkdirAll(\"/usr/local/bin\", 0755); err != nil {\n\t\t\t\t\treturn nil\n\t\t\t\t}\n\t\t\t\treturn os.WriteFile(nerdctlCmdArgs.path, buf, 0755)\n\t\t\t}\n\n\t\t\t// sudo is needed for the default path\n\t\t\tlog.Println(\"/usr/local/bin not writable, sudo password required to install nerdctl binary\")\n\t\t\tif exists && !nerdctlCmdArgs.isColimaScript {\n\t\t\t\tc := cli.CommandInteractive(\"sudo\", \"mv\", nerdctlCmdArgs.path, nerdctlCmdArgs.path+\".moved\")\n\t\t\t\tif err := c.Run(); err != nil {\n\t\t\t\t\treturn fmt.Errorf(\"error backing up existing file: %w\", err)\n\t\t\t\t}\n\t\t\t}\n\t\t\t// prepare dir\n\t\t\t{","sourceCodeStart":109,"sourceCodeEnd":145,"githubUrl":"https://github.com/abiosoft/colima/blob/c3a5f9184d83a197184f897a9f07eb3c01b3bc88/cmd/nerdctl.go#L109-L145","documentation":"In the no-sudo branch of `colima nerdctl install` (taken when /usr/local/bin is writable OR a custom --path is given), an existing target file is first backed up with os.Rename(path, path+\".moved\"). This error wraps a rename failure: the containing directory is not actually writable, the file is locked, or the custom path's directory does not exist.","triggerScenarios":"A custom --path whose parent directory does not exist (rename fails with ENOENT); --path pointing into a read-only mount; the writability probe passing but SIP/permissions still denying rename on macOS; antivirus/file-watcher holding the file open.","commonSituations":"`colima nerdctl install --path ~/some/missing/dir/nerdctl`; systems where /usr/local/bin ownership changed after the probe; corporate endpoint protection locking new executables.","solutions":["Ensure the parent directory of --path exists and is writable: mkdir -p the dir and touch a probe file","Use the default path and let the sudo flow handle it (drop --path), or fix the directory permissions","Pre-move the old file yourself (mv <path> <path>.moved) and re-run `colima nerdctl install --force`"],"exampleFix":"# before\n$ colima nerdctl install --path /opt/bin/nerdctl\nerror: error backing up existing file: rename ...: no such file or directory\n\n# after\n$ sudo mkdir -p /opt/bin\n$ colima nerdctl install --path /opt/bin/nerdctl --force","handlingStrategy":"validation","validationCode":"// verify rename-ability of the target dir before install\nfunc dirWritable(dir string) bool {\n    f, err := os.CreateTemp(dir, \".colima-probe-*\")\n    if err != nil {\n        return false\n    }\n    return os.Remove(f.Name()) == nil\n}\n\nif !dirWritable(filepath.Dir(path)) {\n    // mkdir -p the dir, chmod it, or switch to the default sudo flow\n}","typeGuard":null,"tryCatchPattern":"if err := installCmd.Execute(); err != nil {\n    if strings.Contains(err.Error(), \"error backing up existing file\") && errors.Is(err, fs.ErrPermission) {\n        // pre-move the file manually or fix dir permissions, then retry\n    }\n}","preventionTips":["Ensure the parent of a custom --path exists (mkdir -p) before installing","Verify write access with a temp-file probe, not just an os.Stat on the directory","Pre-move existing targets yourself when automating installs"],"tags":["colima","nerdctl","installation","filesystem","backup"],"backgroundTag":null,"analyzedSha":"c3a5f9184d83a197184f897a9f07eb3c01b3bc88","analyzedAt":"2026-08-15T18:58:08.334Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}