-
Notifications
You must be signed in to change notification settings - Fork 55
/
filter.go
48 lines (36 loc) · 928 Bytes
/
filter.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
package serverHandler
import "os"
func (h *aliasHandler) FilterItems(items []os.FileInfo) []os.FileInfo {
if h.shows == nil &&
h.showDirs == nil &&
h.showFiles == nil &&
h.hides == nil &&
h.hideDirs == nil &&
h.hideFiles == nil {
return items
}
filtered := make([]os.FileInfo, 0, len(items))
for _, item := range items {
name := item.Name()
if h.hides != nil && h.hides.MatchString(name) {
continue
}
if h.hideDirs != nil && item.IsDir() && h.hideDirs.MatchString(name) {
continue
}
if h.hideFiles != nil && !item.IsDir() && h.hideFiles.MatchString(name) {
continue
}
if h.shows != nil && !h.shows.MatchString(name) {
continue
}
if h.showDirs != nil && item.IsDir() && !h.showDirs.MatchString(name) {
continue
}
if h.showFiles != nil && !item.IsDir() && !h.showFiles.MatchString(name) {
continue
}
filtered = append(filtered, item)
}
return filtered
}