Check disk before even trying to run the download

This commit is contained in:
Dane Everitt
2020-12-20 11:08:01 -08:00
parent 17daa2071f
commit 9c53436470
5 changed files with 18 additions and 8 deletions

View File

@@ -60,7 +60,6 @@ func (dl *Download) Execute() error {
dl.cancelFunc = &cancel
defer dl.Cancel()
fnameparts := strings.Split(dl.req.URL.Path, "/")
req, _ := http.NewRequestWithContext(ctx, http.MethodGet, dl.req.URL.String(), nil)
res, err := client.Do(req)
if err != nil {
@@ -70,6 +69,8 @@ func (dl *Download) Execute() error {
if res.StatusCode >= 300 || res.StatusCode < 200 {
return errors.New("downloader: got bad response status from endpoint: " + res.Status)
}
fnameparts := strings.Split(dl.req.URL.Path, "/")
p := filepath.Join(dl.req.Directory, fnameparts[len(fnameparts)-1])
dl.server.Log().WithField("path", p).Debug("writing remote file to disk")
if err := dl.server.Filesystem().Writefile(p, res.Body); err != nil {