Skip to content

Commit 30adc0c

Browse files
committed
fix: fix #534 can't build windows binary file
1 parent 3150a55 commit 30adc0c

File tree

2 files changed

+23
-15
lines changed

2 files changed

+23
-15
lines changed

src/internal/file_operations.go

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import (
66
"os"
77
"path/filepath"
88
"runtime"
9-
"syscall"
9+
"strings"
1010

1111
"github.com/rkoesters/xdg/trash"
1212
variable "github.com/yorukot/superfile/src/config"
@@ -15,21 +15,33 @@ import (
1515

1616
// isSamePartition checks if two paths are on the same filesystem partition
1717
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)
2120
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)
2322
}
2423

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)
2825
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
3034
}
3135

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]))
3345
}
3446

3547
// moveElement moves a file or directory efficiently

src/internal/handle_file_operations.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,11 +49,7 @@ func (m *model) IsRenamingConflicting() bool {
4949
}
5050

5151
_, err := os.Stat(newPath)
52-
if err == nil {
53-
return true
54-
}
55-
56-
return false
52+
return err == nil
5753
}
5854

5955
func (m *model) warnModalForRenaming() {

0 commit comments

Comments
 (0)