-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpath.go
74 lines (60 loc) · 1.21 KB
/
path.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
package main
import (
"os"
"path/filepath"
"strings"
)
func (app *App) removePath(path string) {
for elem := app.dirList.Front(); elem != nil; elem.Next() {
dirPath, ok := elem.Value.(string)
if !ok {
continue
}
if strings.Index(dirPath, path) == 0 {
app.watcher.Remove(dirPath)
app.dirList.Remove(elem)
}
}
return
}
func (app *App) checkDir(e *FileEvent) (bool, error) {
switch e.action {
case "removed", "renamed":
for elem := app.dirList.Front(); elem != nil; elem.Next() {
if elem.Value == e.file {
return true, nil
}
}
return false, nil
default:
fInfo, err := os.Stat(e.file)
if err != nil {
return false, err
}
return fInfo.IsDir(), nil
}
}
// searchExt searchs ext
// return true, if hit serching
func searchExt(fileName string, extList []string) bool {
ext := filepath.Ext(fileName)
if len(ext) <= 1 {
return false
}
for _, e := range extList {
if e == ext[1:] {
return true
}
}
return false
}
func getDirectoryList(path string) ([]string, error) {
result := []string{}
filepath.Walk(path, func(path string, info os.FileInfo, err error) error {
if info.IsDir() {
result = append(result, path)
}
return nil
})
return result, nil
}