Fix bug creating cache dir

This commit is contained in:
James Mills
2021-02-02 08:01:21 +10:00
parent 4383b3125d
commit 82da9eee99

View File

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