-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathoptions.go
145 lines (125 loc) · 3.18 KB
/
options.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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
package gorsn
import (
"regexp"
"sync/atomic"
"time"
)
// eventOps represents optional fields to define which event to produce.
type eventOps struct {
ignoreErrors atomic.Bool
ignoreNoChange atomic.Bool // should not emit event when nothing changed. default to true.
ignoreDelete atomic.Bool
ignoreCreate atomic.Bool
ignoreModify atomic.Bool
ignorePerm atomic.Bool
ignoreFile atomic.Bool // should emit event for regular files.
ignoreFolder atomic.Bool // should emit event for directories.
ignoreSymlink atomic.Bool
ignoreFolderContent atomic.Bool // should emit event for each sub-content of a directory included the directory itself.
}
type Options struct {
queueSize int
maxworkers atomic.Uint32
event eventOps
scanInterval atomic.Value
excludePaths *regexp.Regexp
includePaths *regexp.Regexp
}
func defaultOpts() *Options {
o := &Options{}
o.queueSize = DEFAULT_QUEUE_SIZE
o.maxworkers.Store(DEFAULT_MAX_WORKERS)
o.scanInterval.Store(DEFAULT_SCAN_INTERVAL)
o.excludePaths = nil
o.includePaths = nil
o.event.ignoreNoChange.Store(true)
return o
}
func (o *Options) setup() *Options {
if o == nil {
o = defaultOpts()
return o
}
if o.queueSize <= 0 {
o.queueSize = DEFAULT_QUEUE_SIZE
}
if o.maxworkers.Load() == 0 {
// maxworkers was not set.
o.maxworkers.Store(DEFAULT_MAX_WORKERS)
}
if o.scanInterval.Load() == nil {
// scanInterval was not set.
o.scanInterval.Store(DEFAULT_SCAN_INTERVAL)
}
o.event.ignoreNoChange.Store(true)
return o
}
func RegexOpts(eregex, iregex *regexp.Regexp) *Options {
if eregex != nil && eregex.String() == "" {
eregex = nil
}
if iregex != nil && iregex.String() == "" {
iregex = nil
}
return &Options{excludePaths: eregex, includePaths: iregex}
}
func (o *Options) SetQueueSize(v int) *Options {
o.queueSize = v
return o
}
func (o *Options) SetMaxWorkers(v int) *Options {
if v <= 0 {
o.maxworkers.Store(DEFAULT_MAX_WORKERS)
return o
}
o.maxworkers.Store(uint32(v))
return o
}
func (o *Options) SetScanInterval(v time.Duration) *Options {
if v < 0 {
o.scanInterval.Store(DEFAULT_SCAN_INTERVAL)
return o
}
o.scanInterval.Store(v)
return o
}
func (o *Options) SetIgnoreErrors(v bool) *Options {
o.event.ignoreErrors.Store(v)
return o
}
func (o *Options) SetIgnoreNoChangeEvent(v bool) *Options {
o.event.ignoreNoChange.Store(v)
return o
}
func (o *Options) SetIgnoreDeleteEvent(v bool) *Options {
o.event.ignoreDelete.Store(v)
return o
}
func (o *Options) SetIgnoreCreateEvent(v bool) *Options {
o.event.ignoreCreate.Store(v)
return o
}
func (o *Options) SetIgnoreModifyEvent(v bool) *Options {
o.event.ignoreModify.Store(v)
return o
}
func (o *Options) SetIgnorePermEvent(v bool) *Options {
o.event.ignorePerm.Store(v)
return o
}
func (o *Options) SetIgnoreFileEvent(v bool) *Options {
o.event.ignoreFile.Store(v)
return o
}
func (o *Options) SetIgnoreFolderEvent(v bool) *Options {
o.event.ignoreFolder.Store(v)
return o
}
func (o *Options) SetIgnoreSymlink(v bool) *Options {
o.event.ignoreSymlink.Store(v)
return o
}
func (o *Options) SetIgnoreFolderContentEvent(v bool) *Options {
o.event.ignoreFolderContent.Store(v)
return o
}