coreybutler/nvm-windows · error

failed to copy file: %v

Error message

failed to copy file: %v

What it means

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.

Source

Thrown at src/upgrade/upgrade.go:938

func copyFile(src, dst string) error {
	// Open the source file
	sourceFile, err := os.Open(src)
	if err != nil {
		return fmt.Errorf("failed to open source file: %v", err)
	}
	defer sourceFile.Close()

	// Create the destination file
	destinationFile, err := os.Create(dst)
	if err != nil {
		return fmt.Errorf("failed to create destination file: %v", err)
	}
	defer destinationFile.Close()

	// Copy contents from the source file to the destination file
	_, err = io.Copy(destinationFile, sourceFile)
	if err != nil {
		return fmt.Errorf("failed to copy file: %v", err)
	}

	// Optionally, copy file permissions (this can be skipped if not needed)
	sourceInfo, err := os.Stat(src)
	if err != nil {
		return fmt.Errorf("failed to get source file info: %v", err)
	}

	err = os.Chmod(dst, sourceInfo.Mode())
	if err != nil {
		return fmt.Errorf("failed to set file permissions: %v", err)
	}

	return nil
}

// copyDirContents copies all the contents (files and subdirectories) of a source directory to a destination directory.
func copyDirContents(srcDir, dstDir string) error {

View on GitHub (pinned to 5b18223ca1)

Solutions

  1. Check free space on both the TEMP and destination drives and free space if low.
  2. Whitelist NVM_HOME in antivirus / Controlled Folder Access and retry.
  3. If NVM_HOME is on network storage, move it to a local drive or fix the share.
  4. Retry the upgrade — transient mid-copy locks usually clear.
Defensive patterns

Strategy: retry

Validate before calling

// Check destination free space before starting the upgrade
var stat syscall.Statfs_t // linux; on Windows use GetDiskFreeSpaceEx via golang.org/x/sys/windows
if free := diskFree(filepath.VolumeName(dst)); free < requiredBytes {
    return fmt.Errorf("insufficient disk space: %d free, %d needed", free, requiredBytes)
}

Try / catch

Retry once after a short delay (transient locks); if it persists, check disk space and AV exclusions rather than looping.

Prevention

When it happens

Trigger: 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.

Common situations: Low-disk CI machines mid-upgrade; NVM_HOME on a mapped corporate share; ransomware protection (Controlled Folder Access) silently denying writes to protected locations.

Related errors


AI-assisted analysis of coreybutler/nvm-windows@5b18223ca1 (2026-08-15). Data as JSON: /api/errors/3e6566207bd13d26. Report an issue: GitHub.