Skip to content

Commit

Permalink
worker: detect the status code when downloading a layer and expect 2XX.
Browse files Browse the repository at this point in the history
  • Loading branch information
Quentin-M committed Feb 9, 2016
1 parent 6aa501f commit 343ce39
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions worker/detectors/data.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 343ce39

Please sign in to comment.