Skip to content

Commit

Permalink
fix: ensure data home exists before rules update
Browse files Browse the repository at this point in the history
  • Loading branch information
doron-cohen committed Nov 9, 2020
1 parent 094a3b5 commit cdf5c28
Showing 1 changed file with 14 additions and 0 deletions.
14 changes: 14 additions & 0 deletions internal/utils/fetch.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package utils

import (
"errors"
"fmt"
"io"
"io/ioutil"
"log"
"net/http"
"os"
"path"
)

func Download(src, dest string) error {
Expand All @@ -27,6 +30,17 @@ func Download(src, dest string) error {
return err
}

dir := path.Dir(dest)
fileInfo, err := os.Stat(dir)
if os.IsNotExist(err) {
if err = os.MkdirAll(dir, os.FileMode(0o755)); err != nil {
return err
}
} else if !fileInfo.IsDir() {
text := fmt.Sprintf("Rules file destination directory is a file: %s", dir)
return errors.New(text)
}

err = MoveFile(tempFile.Name(), dest)
if err != nil {
return err
Expand Down

0 comments on commit cdf5c28

Please sign in to comment.