From 343ce39865dc2994c0bd8c4d9f75c5be476fe1b0 Mon Sep 17 00:00:00 2001 From: Quentin Machu Date: Tue, 9 Feb 2016 16:55:56 -0500 Subject: [PATCH] worker: detect the status code when downloading a layer and expect 2XX. --- worker/detectors/data.go | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/worker/detectors/data.go b/worker/detectors/data.go index 23f50e11..d2dd869f 100644 --- a/worker/detectors/data.go +++ b/worker/detectors/data.go @@ -19,12 +19,14 @@ package detectors import ( "fmt" "io" + "math" "net/http" "os" "strings" "sync" cerrors "github.com/coreos/clair/utils/errors" + "github.com/coreos/pkg/capnslog" ) // The DataDetector interface defines a way to detect the required data from input path @@ -38,6 +40,8 @@ type DataDetector interface { var ( dataDetectorsLock sync.Mutex dataDetectors = make(map[string]DataDetector) + + log = capnslog.NewPackageLogger("github.com/coreos/clair", "detectors") ) // RegisterDataDetector provides a way to dynamically register an implementation of a @@ -70,6 +74,14 @@ func DetectData(path string, format string, toExtract []string, maxFileSize int6 if err != nil { return nil, cerrors.ErrCouldNotDownload } + if err != nil { + log.Warningf("could not download layer: %s", err) + return nil, cerrors.ErrCouldNotDownload + } + if math.Floor(float64(r.StatusCode/100)) != 2 { + log.Warningf("could not download layer: got status code %d, expected 2XX", r.StatusCode) + return nil, cerrors.ErrCouldNotDownload + } layerReader = r.Body } else { layerReader, err = os.Open(path)