From 82da9eee99e5ef0fbf67cf64e7c7eb685d470b51 Mon Sep 17 00:00:00 2001 From: James Mills Date: Tue, 2 Feb 2021 08:01:21 +1000 Subject: [PATCH] Fix bug creating cache dir --- internal/scraper.go | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/internal/scraper.go b/internal/scraper.go index cd61c97..a8f4194 100644 --- a/internal/scraper.go +++ b/internal/scraper.go @@ -3,6 +3,7 @@ package internal import ( "fmt" "io/ioutil" + "os" "path/filepath" "regexp" @@ -52,7 +53,14 @@ func Scrape(conf *Config, url string) (*Entry, error) { HTMLContent: article.Content, } - fn := filepath.Join(conf.Data, cacheDir, fmt.Sprintf("%s.json", entry.Hash())) + p := filepath.Join(conf.Data, cacheDir) + if err := os.MkdirAll(p, 0755); err != nil { + log.WithError(err).Error("error creating cache directory") + return nil, fmt.Errorf("error creating cache directory: %w", err) + } + + fn := filepath.Join(p, fmt.Sprintf("%s.json", entry.Hash())) + data, err := entry.Bytes() if err != nil { log.WithError(err).Error("error serializing entry")