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 <wking@tremily.us>

Closes: #686
Approved by: mheon
This commit is contained in:
W. Trevor King 2018-04-27 16:28:19 -07:00 committed by Atomic Bot
parent 68eb128fb0
commit 5676597f40
1 changed files with 4 additions and 0 deletions

View File

@ -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