diff options
| author | Paul Buetow <paul@buetow.org> | 2023-06-18 11:54:59 +0300 |
|---|---|---|
| committer | Paul Buetow <paul@buetow.org> | 2023-06-18 11:54:59 +0300 |
| commit | 1a963283a18f9c3a69c92bf5b424748c9813d6d4 (patch) | |
| tree | a31719cb3ef6b525608f5f3c83d007318a6c7b1c /internal/state.go | |
| parent | faf8b0f8715a280c7f7f98595042fd4897e8da0b (diff) | |
create state dir if it doesnt exist yet
Diffstat (limited to 'internal/state.go')
| -rw-r--r-- | internal/state.go | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/internal/state.go b/internal/state.go index 3735a52..f23c8a4 100644 --- a/internal/state.go +++ b/internal/state.go @@ -6,6 +6,7 @@ import ( "io/ioutil" "log" "os" + "path/filepath" "strings" ) @@ -78,10 +79,18 @@ func (s state) update(result checkResult) { } func (s state) persist() error { + stateDir := filepath.Dir(s.stateFile) + if _, err := os.Stat(stateDir); os.IsNotExist(err) { + if err := os.MkdirAll(stateDir, 0755); err != nil { + return err + } + } + jsonData, err := json.Marshal(s.checks) if err != nil { return err } + return ioutil.WriteFile(s.stateFile, jsonData, os.ModePerm) } |
