yorukot/superfile · error

failed to check partitions: %w

Error message

failed to check partitions: %w

What it means

moveElement first asks isSamePartition whether source and destination share a filesystem; any error from that check is wrapped as 'failed to check partitions'. This is a wrapper around the underlying abs-path/ partition-detection errors, so the root cause is in the %w chain.

Source

Thrown at src/internal/file_operations.go:52

	}

	// For Unix-like systems, we use the same path to check the root partition
	return filepath.VolumeName(absPath1) == filepath.VolumeName(absPath2), nil
}

// getDriveLetter extracts the drive letter from a Windows path
func getDriveLetter(path string) string {
	// Windows paths are usually like "C:\path\to\file"
	// So we need to extract the drive letter (e.g., "C")
	return strings.ToUpper(string(path[0]))
}

// moveElement moves a file or directory efficiently
func moveElement(src, dst string) error {
	// Check if source and destination are on the same partition
	sameDev, err := isSamePartition(src, dst)
	if err != nil {
		return fmt.Errorf("failed to check partitions: %w", err)
	}

	// If on the same partition, attempt to rename (which will use the same inode)
	if sameDev {
		if err = os.Rename(src, dst); err == nil {
			return nil
		}
		// If rename fails, fall back to copy+delete
	}

	// If on different partitions or rename failed, fall back to copy+delete
	err = copyElement(src, dst)
	if err != nil {
		return fmt.Errorf("failed to copy: %w", err)
	}

	err = os.RemoveAll(src)
	if err != nil {

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Read the wrapped %w error for the real cause (abs path vs device check).
  2. Use absolute, well-formed paths for both src and dst.
  3. Verify the destination mount is accessible (df / ls the mount).
  4. Retry after restoring the working directory or remounting the target volume.

Example fix

// before
moveElement("file.txt", "/mnt/netdrv/dest") // mount down
// after
// remount /mnt/netdrv, or pick an accessible destination
moveElement("/data/file.txt", "/mnt/netdrv/dest")
Defensive patterns

Strategy: validation

Validate before calling

for _, p := range []string{src, dst} {
    if !filepath.IsAbs(p) {
        if _, err := os.Getwd(); err != nil {
            return fmt.Errorf("cwd unavailable, resolve %q to absolute first", p)
        }
    }
}
if _, err := os.Stat(filepath.Dir(dst)); err != nil {
    return fmt.Errorf("destination parent inaccessible: %w", err)
}

Type guard

func pathsResolvable(paths ...string) error {
    for _, p := range paths {
        if filepath.IsAbs(p) { continue }
        if _, err := os.Getwd(); err != nil { return err }
    }
    return nil
}

Try / catch

if err := moveElement(src, dst); err != nil {
    if strings.Contains(err.Error(), "failed to check partitions") {
        // fall back to explicit copy+delete with fully resolved paths
        return manualMove(filepathAbs(src), filepathAbs(dst))
    }
    return err
}

Prevention

When it happens

Trigger: moveElement(src, dst) called with paths whose absolute resolution or partition detection fails (e.g. Getwd failure on relative paths, or underlying OS stat/device checks erroring).

Common situations: Moving a file whose cwd was deleted; destination on a flaky mount point (network drive dropped); Windows drive-letter lookup on a malformed path.

Related errors


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