Skip to content

Commit

Permalink
Factor out verifyDownload().
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Apr 26, 2016
1 parent 334c5d3 commit b049e95
Showing 1 changed file with 18 additions and 14 deletions.
32 changes: 18 additions & 14 deletions downloader/download.go
Original file line number Diff line number Diff line change
Expand Up @@ -111,21 +111,8 @@ func (dl *Download) run(req Request) {

if err == nil {
logger.Infof("download complete (%q)", req.URL)

if req.Verify != nil {
err = req.Verify(file)
if errors.IsNotValid(err) {
logger.Errorf("download of %s invalid: %v", req.URL, err)
}
if _, err2 := file.Seek(0, os.SEEK_SET); err2 != nil {
logger.Errorf("failed to seek to beginning of file: %v", err2)
if err == nil {
err = errors.Trace(err2)
}
}
if err != nil {
logger.Infof("download verified (%q)", req.URL)
}
err = verifyDownload(file, req)
}
}

Expand All @@ -140,6 +127,23 @@ func (dl *Download) run(req Request) {
}
}

func verifyDownload(file *os.File, req Request) error {
err := req.Verify(file)
if err != nil {
if errors.IsNotValid(err) {
logger.Errorf("download of %s invalid: %v", req.URL, err)
}
return errors.Trace(err)
}
logger.Infof("download verified (%q)", req.URL)

if _, err := file.Seek(0, os.SEEK_SET); err != nil {
logger.Errorf("failed to seek to beginning of file: %v", err)
return errors.Trace(err)
}
return nil
}

func download(req Request, openBlob func(*url.URL) (io.ReadCloser, error)) (file *os.File, err error) {
logger.Infof("downloading from %s", req.URL)

Expand Down

0 comments on commit b049e95

Please sign in to comment.