From 1e15e2b753a17e50abff23341351e8a07efcbaf1 Mon Sep 17 00:00:00 2001 From: Sebastian Frank Date: Tue, 7 Sep 2021 18:09:05 +0200 Subject: [PATCH] ignoreMissing flag --- config.yml | 1 + main.go | 17 ++++++++++++----- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/config.yml b/config.yml index 6946850..02637fc 100644 --- a/config.yml +++ b/config.yml @@ -7,6 +7,7 @@ directories: events: ["CLOSE_WRITE", "MOVED_TO"] pollingInterval: 60 regex: "/[^\\.][^/]+.xml$" + ignoreMissing: true actions: - id: postXML description: POST xml diff --git a/main.go b/main.go index 0d48037..bd339ef 100644 --- a/main.go +++ b/main.go @@ -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,11 +176,17 @@ func startWatcher(directory *DirectoryConfig) { directory._regexMatches = directory._regex.FindStringSubmatch(p) } if directory._regex == nil || directory._regexMatches != nil { - for _, action := range directory.Actions { - action.Directory = directory - contin, _ := runAction(&action, eventInfo, nil) - if !contin { - break + 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) + if !contin { + break + } } } } else {