Skip to content
This repository has been archived by the owner on Aug 14, 2020. It is now read-only.

Commit

Permalink
do not close the reader
Browse files Browse the repository at this point in the history
Signed-off-by: Antonio Murdaca <runcom@redhat.com>
  • Loading branch information
runcom committed Jul 7, 2016
1 parent da56c93 commit 505cc4f
Showing 1 changed file with 16 additions and 3 deletions.
19 changes: 16 additions & 3 deletions lib/internal/backend/repository/repository2.go
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,11 @@ func validateV1ID(id string) error {
}

func (rb *RepositoryBackend) getLayerV2(layerID string, dockerURL *types.ParsedDockerURL, tmpDir string, copier *progressutil.CopyProgressPrinter) (*os.File, io.ReadCloser, error) {
url := rb.schema + path.Join(dockerURL.IndexURL, "v2", dockerURL.ImageName, "blobs", layerID)
var (
err error
res *http.Response
url = rb.schema + path.Join(dockerURL.IndexURL, "v2", dockerURL.ImageName, "blobs", layerID)
)
req, err := http.NewRequest("GET", url, nil)
if err != nil {
return nil, nil, err
Expand All @@ -488,23 +492,32 @@ func (rb *RepositoryBackend) getLayerV2(layerID string, dockerURL *types.ParsedD
typesV2.MediaTypeOCIRootFS,
}

res, err := rb.makeRequest(req, dockerURL.ImageName, accepting)
res, err = rb.makeRequest(req, dockerURL.ImageName, accepting)
if err != nil {
return nil, nil, err
}

defer func() {
if err != nil {
if res != nil {
res.Body.Close()
}
}
}()

if res.StatusCode == http.StatusTemporaryRedirect || res.StatusCode == http.StatusFound {
location := res.Header.Get("Location")
if location != "" {
req, err = http.NewRequest("GET", location, nil)
if err != nil {
return nil, nil, err
}
res.Body.Close()
res = nil
res, err = rb.makeRequest(req, dockerURL.ImageName, accepting)
if err != nil {
return nil, nil, err
}
defer res.Body.Close()
}
}

Expand Down

0 comments on commit 505cc4f

Please sign in to comment.