diff options
| author | Shulhan <ms@kilabit.info> | 2022-04-20 01:15:18 +0700 |
|---|---|---|
| committer | Shulhan <ms@kilabit.info> | 2022-04-20 01:15:18 +0700 |
| commit | bf2c970904462b35595cf74c40691120e12ac15d (patch) | |
| tree | 9bf2c4e25c0d2ec5fe50b7b5b6c50dc12836f042 | |
| parent | 7d7b0b0fc9eb078001a010dcdab3aa97938806c3 (diff) | |
| download | rescached-bf2c970904462b35595cf74c40691120e12ac15d.tar.xz | |
all: fix error updating hosts block if directory not exist
If the hosts block file never created before and the directory to
hosts block file is not exist, the hostsBlock update method will return
an error.
This changes fix this issue by creating the path to hosts block directory
first before fetching and storing the new update.
| -rw-r--r-- | hosts_block.go | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/hosts_block.go b/hosts_block.go index bc9a238..dc65464 100644 --- a/hosts_block.go +++ b/hosts_block.go @@ -109,6 +109,11 @@ func (hb *hostsBlock) update() (err error) { fmt.Printf("%s %s: updating ...\n", logp, hb.Name) + err = os.MkdirAll(filepath.Dir(hb.file), 0700) + if err != nil { + return fmt.Errorf("%s %s: %w", logp, hb.Name, err) + } + res, err = http.Get(hb.URL) if err != nil { return fmt.Errorf("%s %s: %w", logp, hb.Name, err) |
