Commit a7bc21a3 authored by Steven Allen's avatar Steven Allen

serialfile: fix handling of hidden paths on windows

fixes #11
parent 20be69d9
// +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
}
......@@ -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
}
......@@ -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
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment