{"record":{"id":"d17bd5c3ccb548b2","repo":"coreybutler/nvm-windows","slug":"failed-to-create-destination-file-v","errorCode":null,"errorMessage":"failed to create destination file: %v","messagePattern":"failed to create destination file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upgrade/upgrade.go","lineNumber":931,"sourceCode":"\tif err != nil {\n\t\treturn \"\", err\n\t}\n\n\treturn checksum, nil\n}\n\nfunc copyFile(src, dst string) error {\n\t// Open the source file\n\tsourceFile, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %v\", err)\n\t}\n\tdefer sourceFile.Close()\n\n\t// Create the destination file\n\tdestinationFile, err := os.Create(dst)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %v\", err)\n\t}\n\tdefer destinationFile.Close()\n\n\t// Copy contents from the source file to the destination file\n\t_, err = io.Copy(destinationFile, sourceFile)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to copy file: %v\", err)\n\t}\n\n\t// Optionally, copy file permissions (this can be skipped if not needed)\n\tsourceInfo, err := os.Stat(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to get source file info: %v\", err)\n\t}\n\n\terr = os.Chmod(dst, sourceInfo.Mode())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to set file permissions: %v\", err)","sourceCodeStart":913,"sourceCodeEnd":949,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/upgrade/upgrade.go#L913-L949","documentation":"copyFile failed at os.Create(dst): the destination file could not be created. On Windows this is dominated by sharing violations — the destination exists and is open by a running process (often nvm.exe or node.exe itself), since Windows refuses to create/truncate a file with an active handle. It also fires when the parent directory of dst does not exist or is read-only.","triggerScenarios":"Copying nvm.exe/update.exe over binaries that are currently executing; dst parent directory missing (copyFile does not mkdir parents); NVM_HOME on a read-only or ACL-restricted location; .update hidden directory unwritable.","commonSituations":"Self-update attempted while another nvm command runs in a second terminal; non-admin install under Program Files; .update folder marked read-only by policy; leftover read-only attribute on files extracted from the zip.","solutions":["Stop all nvm/node processes (check Task Manager) and retry the upgrade.","Run the upgrade from an elevated prompt.","Ensure the destination directory exists and is writable (attrib -r on NVM_HOME files if read-only bits were inherited).","Reinstall nvm-windows cleanly if the destination tree is in a bad state."],"exampleFix":"// before\ndestinationFile, err := os.Create(dst)\n\n// after: create parent directories first, then the file\n_ = os.MkdirAll(filepath.Dir(dst), 0755)\ndestinationFile, err := os.Create(dst)","handlingStrategy":"validation","validationCode":"// Ensure parent dir exists and dest is not currently executing\nos.MkdirAll(filepath.Dir(dst), 0755)\nif _, err := os.Stat(dst); err == nil {\n    if out, _ := exec.Command(\"tasklist\", \"/FI\", \"IMAGENAME eq \"+filepath.Base(dst)).Output(); !strings.Contains(string(out), \"No tasks\") {\n        return fmt.Errorf(\"destination %s is in use; close it first\", dst)\n    }\n}","typeGuard":null,"tryCatchPattern":"On Windows sharing violations, instruct closing the destination process rather than retrying in-process; retry only after the lock holder is gone.","preventionTips":["Run self-updates elevated and with all nvm/node terminals closed.","Create parent directories before copying.","Avoid installing NVM_HOME under ACL-restricted paths without admin rights."],"tags":["filesystem","file-lock","windows","upgrade"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}