mirror of
https://github.com/OpenListTeam/OpenList.git
synced 2025-07-18 17:38:07 +08:00
feat: add file visibility checks for windows (#39)
* feat: add file visibility checks for windows * fix: fix build error * refactor: optimize thie ishidden --------- Co-authored-by: Hantong Chen <70561268+cxw620@users.noreply.github.com>
This commit is contained in:
@ -128,11 +128,9 @@ func (d *Local) List(ctx context.Context, dir model.Obj, args model.ListArgs) ([
|
||||
}
|
||||
var files []model.Obj
|
||||
for _, f := range rawFiles {
|
||||
if !d.ShowHidden && strings.HasPrefix(f.Name(), ".") {
|
||||
continue
|
||||
if d.ShowHidden || !isHidden(f, fullPath) {
|
||||
files = append(files, d.FileInfoToObj(ctx, f, args.ReqPath, fullPath))
|
||||
}
|
||||
file := d.FileInfoToObj(ctx, f, args.ReqPath, fullPath)
|
||||
files = append(files, file)
|
||||
}
|
||||
return files, nil
|
||||
}
|
||||
|
12
drivers/local/util_unix.go
Normal file
12
drivers/local/util_unix.go
Normal file
@ -0,0 +1,12 @@
|
||||
//go:build !windows
|
||||
|
||||
package local
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func isHidden(f fs.FileInfo, _ string) bool {
|
||||
return strings.HasPrefix(f.Name(), ".")
|
||||
}
|
22
drivers/local/util_windows.go
Normal file
22
drivers/local/util_windows.go
Normal file
@ -0,0 +1,22 @@
|
||||
//go:build windows
|
||||
|
||||
package local
|
||||
|
||||
import (
|
||||
"io/fs"
|
||||
"path/filepath"
|
||||
"syscall"
|
||||
)
|
||||
|
||||
func isHidden(f fs.FileInfo, fullPath string) bool {
|
||||
filePath := filepath.Join(fullPath, f.Name())
|
||||
namePtr, err := syscall.UTF16PtrFromString(filePath)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
attrs, err := syscall.GetFileAttributes(namePtr)
|
||||
if err != nil {
|
||||
return false
|
||||
}
|
||||
return attrs&syscall.FILE_ATTRIBUTE_HIDDEN != 0
|
||||
}
|
Reference in New Issue
Block a user