yorukot/superfile · error

failed to copy file contents: %w

Error message

failed to copy file contents: %w

What it means

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.

Source

Thrown at src/internal/file_operations.go:151

	return info.Mode()&os.ModeSymlink != 0
}

// copyFile copies a single file
func copyFile(src, dst string, srcInfo os.FileInfo) error {
	srcFile, err := os.Open(src)
	if err != nil {
		return fmt.Errorf("failed to open source file: %w", err)
	}
	defer srcFile.Close()

	dstFile, err := os.OpenFile(dst, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, srcInfo.Mode())
	if err != nil {
		return fmt.Errorf("failed to create destination file: %w", err)
	}
	defer dstFile.Close()

	if _, err := io.Copy(dstFile, srcFile); err != nil {
		return fmt.Errorf("failed to copy file contents: %w", err)
	}
	return nil
}

// pasteDir handles directory copying with progress tracking
func pasteDir(src, dst string, p *processbar.Process, cut bool, processBarModel *processbar.Model) error {
	dst, err := renameIfDuplicate(dst)
	if err != nil {
		return err
	}

	// Check if we can do a fast move within the same partition
	sameDev, err := isSamePartition(src, dst)
	if err == nil && sameDev && cut {
		// For cut operations on same partition, try fast rename first
		err = os.Rename(src, dst)
		if err == nil {
			return nil

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Free space on the destination volume (df -h) and retry the paste.
  2. Check dmesg/system logs for I/O errors; run fsck or replace failing hardware.
  3. Verify the source still exists and is stable (no concurrent writers) and retry.
  4. Reconnect/remount flaky network or USB mounts, then retry the copy.

Example fix

// before
if _, err := io.Copy(dstFile, srcFile); err != nil {
    return fmt.Errorf("failed to copy file contents: %w", err)
}
// after
if _, err := io.Copy(dstFile, srcFile); err != nil {
    if errors.Is(err, syscall.ENOSPC) {
        dstFile.Close()
        os.Remove(dst) // don't leave a partial file
        return fmt.Errorf("destination is full; free space and retry: %w", err)
    }
    dstFile.Close()
    os.Remove(dst)
    return fmt.Errorf("failed to copy file contents: %w", err)
}
Defensive patterns

Strategy: try-catch

Validate before calling

// pre-flight free space check
var st syscall.Statfs_t
if err := syscall.Statfs(filepath.Dir(dst), &st); err == nil {
    avail := int64(st.Bavail) * int64(st.Bsize)
    if srcInfo.Size() >= avail {
        return fmt.Errorf("insufficient space: need %d, have %d", srcInfo.Size(), avail)
    }
}

Try / catch

if err := ops.CopyFile(src, dst); err != nil {
    var pe *fs.PathError
    if errors.As(err, &pe) && errors.Is(pe.Err, syscall.ENOSPC) {
        os.Remove(dst) // clean partial file
        return fmt.Errorf("destination full; free space and retry")
    }
    return err
}

Prevention

When it happens

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

Common situations: 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.

Related errors


AI-assisted analysis of yorukot/superfile@b72f550bc6 (2026-09-01). Data as JSON: /api/errors/6717f61344326e81. Report an issue: GitHub.