yorukot/superfile · error

failed to get absolute path of the second path: %w

Error message

failed to get absolute path of the second path: %w

What it means

Same as the first-path variant: isSamePartition wraps a filepath.Abs failure on the second (destination) path. It occurs only when the destination is relative and the process's working directory cannot be determined.

Source

Thrown at src/internal/file_operations.go:26

	"path/filepath"
	"runtime"
	"strings"

	"github.com/yorukot/superfile/src/internal/ui/processbar"
	"github.com/yorukot/superfile/src/pkg/utils"
)

// isSamePartition checks if two paths are on the same filesystem partition
func isSamePartition(path1, path2 string) (bool, error) {
	// Get the absolute path to handle relative paths
	absPath1, err := filepath.Abs(path1)
	if err != nil {
		return false, fmt.Errorf("failed to get absolute path of the first path: %w", err)
	}

	absPath2, err := filepath.Abs(path2)
	if err != nil {
		return false, fmt.Errorf("failed to get absolute path of the second path: %w", err)
	}

	if runtime.GOOS == utils.OsWindows {
		// On Windows, we can check if both paths are on the same drive (same letter)
		drive1 := getDriveLetter(absPath1)
		drive2 := getDriveLetter(absPath2)
		return drive1 == drive2, nil
	}

	// 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]))

View on GitHub (pinned to b72f550bc6)

Solutions

  1. Pass an absolute destination path.
  2. Make sure the working directory exists before the operation.
  3. Recreate or re-enter a valid directory for the process.
  4. Pre-resolve relative paths with filepath.Abs yourself and handle the error at the UI layer.

Example fix

// before
pasteDir(src, "../backup") // cwd gone
// after
pasteDir(src, "/mnt/backup")
Defensive patterns

Strategy: validation

Validate before calling

if !filepath.IsAbs(dst) {
    if _, err := os.Getwd(); err != nil {
        return fmt.Errorf("cannot resolve relative dst %q: %w", dst, err)
    }
    dst, _ = filepath.Abs(dst)
}

Type guard

func isAbsPath(p string) bool { return filepath.IsAbs(p) }

Try / catch

if err := pasteDir(src, dst); err != nil {
    var pathErr *fs.PathError
    if errors.As(err, &pathErr) {
        log.Errorf("path resolution failed for %s: %v", pathErr.Path, pathErr.Err)
        return pasteDir(src, mustAbs(dst))
    }
    return err
}

Prevention

When it happens

Trigger: moveElement or pasteDir call isSamePartition with a relative path2 while filepath.Abs(path2) fails because os.Getwd fails (deleted/unreadable cwd).

Common situations: Paste target given as a relative path while the app's cwd was removed; daemon running from an unmounted directory; typos resolved relative to a dead cwd.

Related errors


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