fix(platform): normalize native paths for storage and backup validation

This commit is contained in:
eezd committed 2026-10-27 15:03:57 +08:00
1 parent bea53ce3c8
commit 1a8f70ca13
9 files changed
+120 -8

No files matched your search

+1 -1
View File
@@ -18,7 +18,7 @@ func TestAvailableBytes(t *testing.T) {
}
func TestLocalPath(t *testing.T) {
for _, name := range []string{"notes/中文 note.md", "vault/.rawmark/tree-icons.json"} {
for _, name := range []string{"notes/中文 note.md", "vault/.rawmark/tree-icons.json", "vault/.rawmark/trash/id/meta.json"} {
if !IsLocalPath(name) {
t.Fatalf("valid path rejected: %s", name)
}
+3 -1
View File
@@ -21,7 +21,9 @@ func IsLocalPath(name string) bool {
}
}
for _, part := range strings.Split(name, "/") {
if strings.HasSuffix(part, " ") || strings.HasSuffix(part, ".") {
// Reject device basenames on every supported Windows version, including extensions.
base, _, _ := strings.Cut(part, ".")
if (base != "" && !filepath.IsLocal(strings.TrimRight(base, " "))) || strings.HasSuffix(part, " ") || strings.HasSuffix(part, ".") {
return false
}
}
+9 -2
View File
@@ -1,6 +1,10 @@
package fileutil
import "golang.org/x/sys/windows"
import (
"os"
"golang.org/x/sys/windows"
)
// AvailableBytes returns disk space available to the current user.
func AvailableBytes(dir string) (uint64, error) {
@@ -10,5 +14,8 @@ func AvailableBytes(dir string) (uint64, error) {
}
var available uint64
err = windows.GetDiskFreeSpaceEx(name, &available, nil, nil)
return available, err
if err != nil {
return 0, &os.PathError{Op: "GetDiskFreeSpaceEx", Path: dir, Err: err}
}
return available, nil
}