Check disk space before trying a write from the downloader; don't make empty directories if we can't even write the file
This commit is contained in:
@@ -66,10 +66,19 @@ func (dl *Download) Execute() error {
|
||||
return errors.New("downloader: failed opening request to download file")
|
||||
}
|
||||
defer res.Body.Close()
|
||||
if res.StatusCode >= 300 || res.StatusCode < 200 {
|
||||
if res.StatusCode != http.StatusOK {
|
||||
return errors.New("downloader: got bad response status from endpoint: " + res.Status)
|
||||
}
|
||||
|
||||
// If there is a Content-Length header on this request go ahead and check that we can
|
||||
// even write the whole file before beginning this process. If there is no header present
|
||||
// we'll just have to give it a spin and see how it goes.
|
||||
if res.ContentLength > 0 {
|
||||
if err := dl.server.Filesystem().HasSpaceFor(res.ContentLength); err != nil {
|
||||
return errors.WrapIf(err, "downloader: failed to write file: not enough space")
|
||||
}
|
||||
}
|
||||
|
||||
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")
|
||||
|
||||
Reference in New Issue
Block a user