Skip to content

Commit

Permalink
Merge pull request #18418 from aaronlehmann/no-head-requests
Browse files Browse the repository at this point in the history
Avoid a HEAD request for each layer in a v2 pull
  • Loading branch information
calavera committed Dec 4, 2015
2 parents a4817b8 + 3958980 commit 82c4708
Showing 1 changed file with 15 additions and 8 deletions.
23 changes: 15 additions & 8 deletions distribution/pull_v2.go
Expand Up @@ -130,14 +130,6 @@ func (p *v2Puller) download(di *downloadInfo) {

blobs := p.repo.Blobs(context.Background())

desc, err := blobs.Stat(context.Background(), di.digest)
if err != nil {
logrus.Debugf("Error statting layer: %v", err)
di.err <- err
return
}
di.size = desc.Size

layerDownload, err := blobs.Open(context.Background(), di.digest)
if err != nil {
logrus.Debugf("Error fetching layer: %v", err)
Expand All @@ -146,6 +138,21 @@ func (p *v2Puller) download(di *downloadInfo) {
}
defer layerDownload.Close()

di.size, err = layerDownload.Seek(0, os.SEEK_END)
if err != nil {
// Seek failed, perhaps because there was no Content-Length
// header. This shouldn't fail the download, because we can
// still continue without a progress bar.
di.size = 0
} else {
// Restore the seek offset at the beginning of the stream.
_, err = layerDownload.Seek(0, os.SEEK_SET)
if err != nil {
di.err <- err
return
}
}

verifier, err := digest.NewDigestVerifier(di.digest)
if err != nil {
di.err <- err
Expand Down

0 comments on commit 82c4708

Please sign in to comment.