6
6
"os"
7
7
"path/filepath"
8
8
"runtime"
9
- "syscall "
9
+ "strings "
10
10
11
11
"github.com/rkoesters/xdg/trash"
12
12
variable "github.com/yorukot/superfile/src/config"
@@ -15,21 +15,33 @@ import (
15
15
16
16
// isSamePartition checks if two paths are on the same filesystem partition
17
17
func isSamePartition (path1 , path2 string ) (bool , error ) {
18
- var stat1 , stat2 syscall.Stat_t
19
-
20
- err := syscall .Stat (path1 , & stat1 )
18
+ // Get the absolute path to handle relative paths
19
+ absPath1 , err := filepath .Abs (path1 )
21
20
if err != nil {
22
- return false , fmt .Errorf ("failed to stat first path: %v" , err )
21
+ return false , fmt .Errorf ("failed to get absolute path of the first path: %v" , err )
23
22
}
24
23
25
- // For the destination, we need to check its parent directory if it doesn't exist yet
26
- path2Parent := filepath .Dir (path2 )
27
- err = syscall .Stat (path2Parent , & stat2 )
24
+ absPath2 , err := filepath .Abs (path2 )
28
25
if err != nil {
29
- return false , fmt .Errorf ("failed to stat second path: %v" , err )
26
+ return false , fmt .Errorf ("failed to get absolute path of the second path: %v" , err )
27
+ }
28
+
29
+ if runtime .GOOS == "windows" {
30
+ // On Windows, we can check if both paths are on the same drive (same letter)
31
+ drive1 := getDriveLetter (absPath1 )
32
+ drive2 := getDriveLetter (absPath2 )
33
+ return drive1 == drive2 , nil
30
34
}
31
35
32
- return stat1 .Dev == stat2 .Dev , nil
36
+ // For Unix-like systems, we use the same path to check the root partition
37
+ return filepath .VolumeName (absPath1 ) == filepath .VolumeName (absPath2 ), nil
38
+ }
39
+
40
+ // getDriveLetter extracts the drive letter from a Windows path
41
+ func getDriveLetter (path string ) string {
42
+ // Windows paths are usually like "C:\path\to\file"
43
+ // So we need to extract the drive letter (e.g., "C")
44
+ return strings .ToUpper (string (path [0 ]))
33
45
}
34
46
35
47
// moveElement moves a file or directory efficiently
0 commit comments