{"record":{"id":"3e6566207bd13d26","repo":"coreybutler/nvm-windows","slug":"failed-to-copy-file-v","errorCode":null,"errorMessage":"failed to copy file: %v","messagePattern":"failed to copy file: (.+?)","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/upgrade/upgrade.go","lineNumber":938,"sourceCode":"func 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)\n\t}\n\n\treturn nil\n}\n\n// copyDirContents copies all the contents (files and subdirectories) of a source directory to a destination directory.\nfunc copyDirContents(srcDir, dstDir string) error {","sourceCodeStart":920,"sourceCodeEnd":956,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/upgrade/upgrade.go#L920-L956","documentation":"copyFile failed during io.Copy while streaming bytes from source to destination. Both files opened successfully, but the read or write failed mid-transfer. Typical culprits are disk full, an AV scanner locking one handle mid-copy, a source file deleted between open and read, or an SMB/network-share glitch when NVM_HOME or TEMP sits on remote storage.","triggerScenarios":"Destination disk fills exactly during the copy (large node distributions); antivirus re-scanning and locking the half-written destination; source on a ramdisk/network mount that disconnects; Windows Defender controlled-folder-access blocking writes to protected dirs.","commonSituations":"Low-disk CI machines mid-upgrade; NVM_HOME on a mapped corporate share; ransomware protection (Controlled Folder Access) silently denying writes to protected locations.","solutions":["Check free space on both the TEMP and destination drives and free space if low.","Whitelist NVM_HOME in antivirus / Controlled Folder Access and retry.","If NVM_HOME is on network storage, move it to a local drive or fix the share.","Retry the upgrade — transient mid-copy locks usually clear."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Check destination free space before starting the upgrade\nvar stat syscall.Statfs_t // linux; on Windows use GetDiskFreeSpaceEx via golang.org/x/sys/windows\nif free := diskFree(filepath.VolumeName(dst)); free < requiredBytes {\n    return fmt.Errorf(\"insufficient disk space: %d free, %d needed\", free, requiredBytes)\n}","typeGuard":null,"tryCatchPattern":"Retry once after a short delay (transient locks); if it persists, check disk space and AV exclusions rather than looping.","preventionTips":["Keep >=2x the release size free on TEMP and install drives.","Whitelist NVM_HOME in antivirus and Controlled Folder Access.","Keep NVM_HOME on local, not network, storage."],"tags":["filesystem","disk-full","antivirus","upgrade"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}