Skip to content
This repository has been archived by the owner on Mar 29, 2023. It is now read-only.

Commit

Permalink
serialfile: fix handling of hidden paths on windows
Browse files Browse the repository at this point in the history
fixes #11
  • Loading branch information
Stebalien committed Aug 16, 2019
1 parent 20be69d commit a7bc21a
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 28 deletions.
19 changes: 9 additions & 10 deletions is_hidden.go
Original file line number Diff line number Diff line change
@@ -1,18 +1,17 @@
// +build !windows
//+build !windows

package files

import (
"path/filepath"
"strings"
"os"
)

func IsHidden(name string, f Node) bool {
fName := filepath.Base(name)

if strings.HasPrefix(fName, ".") && len(fName) > 1 {
return true
func isHidden(fi os.FileInfo) bool {
fName := fi.Name()
switch fName {
case "", ".", "..":
return false
default:
return fName[0] == '.'
}

return false
}
27 changes: 10 additions & 17 deletions is_hidden_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,33 +3,26 @@
package files

import (
"path/filepath"
"strings"
"os"

windows "golang.org/x/sys/windows"
)

func IsHidden(name string, f Node) bool {

fName := filepath.Base(name)
func isHidden(fi os.FileInfo) bool {
fName := fi.Name()
switch fName {
case "", ".", "..":
return false
}

if strings.HasPrefix(fName, ".") && len(fName) > 1 {
if fName[0] == '.' {
return true
}

fi, ok := f.(FileInfo)
wi, ok := fi.Sys().(*windows.Win32FileAttributeData)
if !ok {
return false
}

p, e := windows.UTF16PtrFromString(fi.AbsPath())
if e != nil {
return false
}

attrs, e := windows.GetFileAttributes(p)
if e != nil {
return false
}
return attrs&windows.FILE_ATTRIBUTE_HIDDEN != 0
return wi.FileAttributes&windows.FILE_ATTRIBUTE_HIDDEN != 0
}
2 changes: 1 addition & 1 deletion serialfile.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func (it *serialIterator) Next() bool {

stat := it.files[0]
it.files = it.files[1:]
for !it.handleHiddenFiles && strings.HasPrefix(stat.Name(), ".") {
for !it.handleHiddenFiles && isHidden(stat) {
if len(it.files) == 0 {
return false
}
Expand Down

0 comments on commit a7bc21a

Please sign in to comment.