-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
69 lines (57 loc) · 1.21 KB
/
helpers.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
package gorsn
import (
"io/fs"
"path/filepath"
)
func getPathType(fm fs.FileMode) pathType {
switch {
case fm.IsDir() || fm&fs.ModeDir != 0:
return DIR
case fm.IsRegular():
return FILE
case fm&fs.ModeSymlink != 0:
return SYMLINK
default:
return UNSUPPORTED
}
}
func (sn *snotifier) finalize() {
sn.stopping.Store(true)
close(sn.stop)
close(sn.iqueue)
close(sn.queue)
sn.wg.Wait()
sn.flush()
sn.running.Store(false)
sn.stopping.Store(false)
sn.paused.Store(false)
sn.ready = false
}
func (sn *snotifier) check(s string, t pathType, err error) (bool, error) {
if t == UNSUPPORTED {
return true, nil
}
if s == sn.root {
// skip root folder.
return true, nil
}
if sn.opts.excludePaths != nil && sn.opts.excludePaths.MatchString(s) {
return true, nil
}
if sn.opts.includePaths != nil && !sn.opts.includePaths.MatchString(s) {
return true, nil
}
if t == FILE && sn.opts.event.ignoreFile.Load() {
return true, nil
}
if t == DIR && sn.opts.event.ignoreFolderContent.Load() {
return true, filepath.SkipDir
}
if t == DIR && sn.opts.event.ignoreFolder.Load() {
return true, nil
}
if t == SYMLINK && sn.opts.event.ignoreSymlink.Load() {
return true, nil
}
return false, nil
}