-
Notifications
You must be signed in to change notification settings - Fork 0
/
pathupgrade.go
52 lines (44 loc) · 959 Bytes
/
pathupgrade.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
package filersync
import (
"time"
)
var (
UpgradeInterval = time.Second
)
func KeepReturnNewPath(path string) (pathchan chan []string) {
pathchan = make(chan []string)
go keepReturnNewpath(path, pathchan)
return
}
func keepReturnNewpath(path string, pathchan chan []string) {
var tmpFileList []string
for {
fileList, err := SelectPath(path)
if err != nil { panic(err) }
if fileListChanged(fileList, &tmpFileList) {
pathchan <- fileList
}
time.Sleep(UpgradeInterval)
}
}
func fileListChanged(fileList []string, tmpFileList *[]string) bool {
if tmpFileList == nil {
*tmpFileList = fileList
return true
}
if len(*tmpFileList) != len(fileList) {
*tmpFileList = fileList
return true
}
for _, f := range *tmpFileList {
if ! inArray(f, fileList) {
*tmpFileList = fileList
return true
}
}
return false
}
func inArray(a string, b []string) bool {
for _, c := range b { if c == a { return true } }
return false
}