{"record":{"id":"c6e089c5e940ac58","repo":"yorukot/superfile","slug":"failed-to-get-absolute-path-of-the-second-path-w","errorCode":null,"errorMessage":"failed to get absolute path of the second path: %w","messagePattern":"failed to get absolute path of the second path: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"src/internal/file_operations.go","lineNumber":26,"sourceCode":"\t\"path/filepath\"\n\t\"runtime\"\n\t\"strings\"\n\n\t\"github.com/yorukot/superfile/src/internal/ui/processbar\"\n\t\"github.com/yorukot/superfile/src/pkg/utils\"\n)\n\n// isSamePartition checks if two paths are on the same filesystem partition\nfunc isSamePartition(path1, path2 string) (bool, error) {\n\t// Get the absolute path to handle relative paths\n\tabsPath1, err := filepath.Abs(path1)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to get absolute path of the first path: %w\", err)\n\t}\n\n\tabsPath2, err := filepath.Abs(path2)\n\tif err != nil {\n\t\treturn false, fmt.Errorf(\"failed to get absolute path of the second path: %w\", err)\n\t}\n\n\tif runtime.GOOS == utils.OsWindows {\n\t\t// On Windows, we can check if both paths are on the same drive (same letter)\n\t\tdrive1 := getDriveLetter(absPath1)\n\t\tdrive2 := getDriveLetter(absPath2)\n\t\treturn drive1 == drive2, nil\n\t}\n\n\t// For Unix-like systems, we use the same path to check the root partition\n\treturn filepath.VolumeName(absPath1) == filepath.VolumeName(absPath2), nil\n}\n\n// getDriveLetter extracts the drive letter from a Windows path\nfunc getDriveLetter(path string) string {\n\t// Windows paths are usually like \"C:\\path\\to\\file\"\n\t// So we need to extract the drive letter (e.g., \"C\")\n\treturn strings.ToUpper(string(path[0]))","sourceCodeStart":8,"sourceCodeEnd":44,"githubUrl":"https://github.com/yorukot/superfile/blob/b72f550bc6e75913f48eb49fdd258e1a2df2fe88/src/internal/file_operations.go#L8-L44","documentation":"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.","triggerScenarios":"moveElement or pasteDir call isSamePartition with a relative path2 while filepath.Abs(path2) fails because os.Getwd fails (deleted/unreadable cwd).","commonSituations":"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.","solutions":["Pass an absolute destination path.","Make sure the working directory exists before the operation.","Recreate or re-enter a valid directory for the process.","Pre-resolve relative paths with filepath.Abs yourself and handle the error at the UI layer."],"exampleFix":"// before\npasteDir(src, \"../backup\") // cwd gone\n// after\npasteDir(src, \"/mnt/backup\")","handlingStrategy":"validation","validationCode":"if !filepath.IsAbs(dst) {\n    if _, err := os.Getwd(); err != nil {\n        return fmt.Errorf(\"cannot resolve relative dst %q: %w\", dst, err)\n    }\n    dst, _ = filepath.Abs(dst)\n}","typeGuard":"func isAbsPath(p string) bool { return filepath.IsAbs(p) }","tryCatchPattern":"if err := pasteDir(src, dst); err != nil {\n    var pathErr *fs.PathError\n    if errors.As(err, &pathErr) {\n        log.Errorf(\"path resolution failed for %s: %v\", pathErr.Path, pathErr.Err)\n        return pasteDir(src, mustAbs(dst))\n    }\n    return err\n}","preventionTips":["Normalize user-supplied destinations to absolute paths at the input boundary.","Run paste/move operations with a guaranteed-valid working directory.","Reject relative paths in configuration with a clear validation message.","Test file operations from a deleted-cwd scenario in CI."],"tags":["paths","filesystem","go"],"backgroundTag":"working-directory-missing","analyzedSha":"b72f550bc6e75913f48eb49fdd258e1a2df2fe88","analyzedAt":"2026-09-01T04:38:08.254Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}