From 5676597f40b61a71704b7f509bd71053d936eaa9 Mon Sep 17 00:00:00 2001 From: "W. Trevor King" Date: Fri, 27 Apr 2018 16:28:19 -0700 Subject: hooks/read: Ignore IsNotExist for JSON files in ReadDir If a .json file existed when we called ioutil.ReadDir but that file has been removed by the time we get around to calling Read on it, silently ignore the file. Iterating through all the files in the directory shouldn't take particularly long, so this is an unlikely corner case. And when it happens, silently ignoring the file gives the same outcome as you'd have gotten if the parallel remove had happened slightly earlier before the ioutil.ReadDir call. Signed-off-by: W. Trevor King Closes: #686 Approved by: mheon --- pkg/hooks/read.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/pkg/hooks/read.go b/pkg/hooks/read.go index fab37351b..29953ac5d 100644 --- a/pkg/hooks/read.go +++ b/pkg/hooks/read.go @@ -5,6 +5,7 @@ import ( "encoding/json" "fmt" "io/ioutil" + "os" "path/filepath" "strings" @@ -71,6 +72,9 @@ func ReadDir(path string, hooks map[string]*current.Hook) error { if err == ErrNoJSONSuffix { continue } + if os.IsNotExist(err) { + continue + } return err } hooks[file.Name()] = hook -- cgit v1.2.3-54-g00ecf