{"record":{"id":"d0f29af7e8edfc72","repo":"coreybutler/nvm-windows","slug":"failed-to-copy-directory-w","errorCode":null,"errorMessage":"failed to copy directory: %w","messagePattern":"failed to copy directory: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/utility/rename.go","lineNumber":28,"sourceCode":"func Rename(old, new string) error {\n\told_drive := filepath.VolumeName(old)\n\tnew_drive := filepath.VolumeName(new)\n\n\tif old_drive == new_drive {\n\t\treturn os.Rename(old, new)\n\t}\n\n\t// Get file or directory info\n\tinfo, err := os.Stat(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to stat source: %w\", err)\n\t}\n\n\t// If old is a directory, copy recursively\n\tif info.IsDir() {\n\t\terr = copyDir(old, new)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy directory: %w\", err)\n\t\t}\n\t} else {\n\t\t// Otherwise, copy a single file\n\t\terr = copyFile(old, new)\n\t\tif err != nil {\n\t\t\treturn fmt.Errorf(\"failed to copy file: %w\", err)\n\t\t}\n\t}\n\n\t// Remove the original source\n\terr = os.RemoveAll(old)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to remove source: %w\", err)\n\t}\n\n\treturn nil\n}\n","sourceCodeStart":10,"sourceCodeEnd":46,"githubUrl":"https://github.com/coreybutler/nvm-windows/blob/5b18223ca19ff50d707f35410dbc6bd440a9f74d/src/utility/rename.go#L10-L46","documentation":"After a successful os.Stat confirms the source is a directory, Rename() delegates to copyDir() to recursively copy it across volumes. This error means the recursive copy of at least one entry (or a subdirectory MkdirAll/ReadDir) failed; the wrapped chain (e.g. 'failed to read source directory: ...' or 'failed to copy file: ...') identifies the exact failing entry.","triggerScenarios":"utility.Rename(old, new) with different volume names where old is a directory, and copyDir fails: source dir becomes unreadable mid-copy (node.exe running from it), destination disk full, or a file inside is locked.","commonSituations":"Moving a node version directory between drives while a node process is running from it; destination drive out of space; antivirus scanning files during the copy; read-only attribute on files under the source tree.","solutions":["Stop all node/npm processes so files in the version directory are not locked, then retry.","Unwrap the error chain to find the failing entry — fix that specific file's lock/permission issue.","Free space on the destination volume if the wrapped error is 'There is not enough space on the disk'.","Retry from an elevated prompt if any wrapped error is 'Access is denied'."],"exampleFix":null,"handlingStrategy":"retry","validationCode":"// Verify the tree is copyable: no running executables and destination has space\nfunc canCopyDir(src, dst string) error {\n    if _, err := os.ReadDir(src); err != nil { return err }\n    if free := diskFree(dst); free <= neededSize(src) { return errors.New(\"insufficient space\") }\n    return nil\n}","typeGuard":null,"tryCatchPattern":"err := utility.Rename(old, new)\nif err != nil && strings.Contains(err.Error(), \"failed to copy directory\") {\n    // unwrap chain, unlock the named entry (kill node.exe), then retry once\n    time.Sleep(time.Second)\n    err = utility.Rename(old, new)\n}","preventionTips":["Stop node processes before switching versions across drives.","Ensure destination volume free space exceeds the version tree size.","Add antivirus exclusions for NVM_HOME to avoid mid-copy locks."],"tags":["filesystem","copy","directory","cross-volume","windows"],"backgroundTag":null,"analyzedSha":"5b18223ca19ff50d707f35410dbc6bd440a9f74d","analyzedAt":"2026-08-15T10:06:51.428Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}