{"record":{"id":"6717f61344326e81","repo":"yorukot/superfile","slug":"failed-to-copy-file-contents-w","errorCode":null,"errorMessage":"failed to copy file contents: %w","messagePattern":"failed to copy file contents: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations.go","lineNumber":151,"sourceCode":"\treturn info.Mode()&os.ModeSymlink != 0\n}\n\n// copyFile copies a single file\nfunc copyFile(src, dst string, srcInfo os.FileInfo) error {\n\tsrcFile, err := os.Open(src)\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to open source file: %w\", err)\n\t}\n\tdefer srcFile.Close()\n\n\tdstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, srcInfo.Mode())\n\tif err != nil {\n\t\treturn fmt.Errorf(\"failed to create destination file: %w\", err)\n\t}\n\tdefer dstFile.Close()\n\n\tif _, err := io.Copy(dstFile, srcFile); err != nil {\n\t\treturn fmt.Errorf(\"failed to copy file contents: %w\", err)\n\t}\n\treturn nil\n}\n\n// pasteDir handles directory copying with progress tracking\nfunc pasteDir(src, dst string, p *processbar.Process, cut bool, processBarModel *processbar.Model) error {\n\tdst, err := renameIfDuplicate(dst)\n\tif err != nil {\n\t\treturn err\n\t}\n\n\t// Check if we can do a fast move within the same partition\n\tsameDev, err := isSamePartition(src, dst)\n\tif err == nil && sameDev && cut {\n\t\t// For cut operations on same partition, try fast rename first\n\t\terr = os.Rename(src, dst)\n\t\tif err == nil {\n\t\t\treturn nil","sourceCodeStart":133,"sourceCodeEnd":169,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations.go#L133-L169","documentation":"copyFile wraps io.Copy(dstFile, srcFile) failures, meaning the data transfer itself failed after both files were opened successfully. Typical wrapped causes are ENOSPC (disk full), EIO (read/write hardware error), or the source being truncated/removed mid-read.","triggerScenarios":"Pasting large files onto a full destination filesystem; I/O errors on flaky disks or USB drives; source file deleted or shrunk by another process while the copy is streaming.","commonSituations":"Disk-full on the target volume during big pastes; network mounts dropping mid-copy; external drives disconnecting; copying from /proc-like files that report huge sizes.","solutions":["Free space on the destination volume (df -h) and retry the paste.","Check dmesg/system logs for I/O errors; run fsck or replace failing hardware.","Verify the source still exists and is stable (no concurrent writers) and retry.","Reconnect/remount flaky network or USB mounts, then retry the copy."],"exampleFix":"// before\nif _, err := io.Copy(dstFile, srcFile); err != nil {\n    return fmt.Errorf(\"failed to copy file contents: %w\", err)\n}\n// after\nif _, err := io.Copy(dstFile, srcFile); err != nil {\n    if errors.Is(err, syscall.ENOSPC) {\n        dstFile.Close()\n        os.Remove(dst) // don't leave a partial file\n        return fmt.Errorf(\"destination is full; free space and retry: %w\", err)\n    }\n    dstFile.Close()\n    os.Remove(dst)\n    return fmt.Errorf(\"failed to copy file contents: %w\", err)\n}","handlingStrategy":"try-catch","validationCode":"// pre-flight free space check\nvar st syscall.Statfs_t\nif err := syscall.Statfs(filepath.Dir(dst), &st); err == nil {\n    avail := int64(st.Bavail) * int64(st.Bsize)\n    if srcInfo.Size() >= avail {\n        return fmt.Errorf(\"insufficient space: need %d, have %d\", srcInfo.Size(), avail)\n    }\n}","typeGuard":null,"tryCatchPattern":"if err := ops.CopyFile(src, dst); err != nil {\n    var pe *fs.PathError\n    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOSPC) {\n        os.Remove(dst) // clean partial file\n        return fmt.Errorf(\"destination full; free space and retry\")\n    }\n    return err\n}","preventionTips":["Check free space (df / Statfs) before large pastes.","Clean up partial destination files after failed copies.","Watch for flaky network/USB mounts and remount before heavy I/O."],"tags":["go","filesystem","copy","io"],"backgroundTag":"disk-full","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}