Skip to content

Commit b45c211

Browse files
YouAlliotTech
authored andcommitted
refactor: improve file listing and add platform-specific hidden file handling
- Updated the List function in driver.go to streamline hidden file filtering based on the ShowHidden flag. - Introduced isHidden utility functions in util_unix.go and util_windows.go to handle hidden file detection for Unix and Windows platforms respectively.
1 parent d77165b commit b45c211

3 files changed

Lines changed: 36 additions & 4 deletions

File tree

drivers/local/driver.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -128,11 +128,9 @@ func (d *Local) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
128128
}
129129
var files []model.Obj
130130
for _, f := range rawFiles {
131-
if !d.ShowHidden && strings.HasPrefix(f.Name(), ".") {
132-
continue
131+
if d.ShowHidden || !isHidden(f, fullPath) {
132+
files = append(files, d.FileInfoToObj(ctx, f, args.ReqPath, fullPath))
133133
}
134-
file := d.FileInfoToObj(ctx, f, args.ReqPath, fullPath)
135-
files = append(files, file)
136134
}
137135
return files, nil
138136
}

drivers/local/util_unix.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
//go:build !windowsAdd commentMore actions
2+
3+
package local
4+
5+
import (
6+
"io/fs"
7+
"strings"
8+
)
9+
10+
func isHidden(f fs.FileInfo, _ string) bool {
11+
return strings.HasPrefix(f.Name(), ".")
12+
}

drivers/local/util_windows.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build windows
2+
3+
package local
4+
5+
import (
6+
"io/fs"
7+
"path/filepath"
8+
"syscall"
9+
)
10+
11+
func isHidden(f fs.FileInfo, fullPath string) bool {
12+
filePath := filepath.Join(fullPath, f.Name())
13+
namePtr, err := syscall.UTF16PtrFromString(filePath)
14+
if err != nil {
15+
return false
16+
}
17+
attrs, err := syscall.GetFileAttributes(namePtr)
18+
if err != nil {
19+
return false
20+
}
21+
return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0
22+
}

0 commit comments

Comments
 (0)