ignoreMissing flag

This commit is contained in:
Sebastian Frank 2021-09-07 18:09:05 +02:00
parent 50b1c7205d
commit 1e15e2b753
Signed by: apairon
GPG Key ID: A0E05A8199CE3F57
2 changed files with 13 additions and 5 deletions

View File

@ -7,6 +7,7 @@ directories:
events: ["CLOSE_WRITE", "MOVED_TO"]
pollingInterval: 60
regex: "/[^\\.][^/]+.xml$"
ignoreMissing: true
actions:
- id: postXML
description: POST xml

View File

@ -57,6 +57,7 @@ type DirectoryConfig struct {
Events []string
PollingInterval *int64 `yaml:"pollingInterval"`
Regex *string
IgnoreMissing bool
_regex *regexp.Regexp
_regexMatches []string
Actions []ActionConfig
@ -175,6 +176,11 @@ func startWatcher(directory *DirectoryConfig) {
directory._regexMatches = directory._regex.FindStringSubmatch(p)
}
if directory._regex == nil || directory._regexMatches != nil {
var statErr error
if directory.IgnoreMissing {
_, statErr = os.Stat(p)
}
if directory.IgnoreMissing || !os.IsNotExist(statErr) {
for _, action := range directory.Actions {
action.Directory = directory
contin, _ := runAction(&action, eventInfo, nil)
@ -182,6 +188,7 @@ func startWatcher(directory *DirectoryConfig) {
break
}
}
}
} else {
log.Printf("[ INFO ] path=\"%s\" info=\"no regex match\"\n", p)
}