1
0
Fork 0
mirror of https://github.com/moby/moby.git synced 2022-11-09 12:21:53 -05:00

Avoid a HEAD request for each layer in a v2 pull

We were calling Stat for each layer to get the size so we could indicate
progress, but https://github.com/docker/distribution/pull/1226 made it
possible to get the length from the GET request that Open initiates.

Saving one round-trip per layer should make pull operations slightly
faster and more robust.

Signed-off-by: Aaron Lehmann <aaron.lehmann@docker.com>
This commit is contained in:
Aaron Lehmann 2015-12-03 18:23:21 -08:00
parent c80d03db77
commit 39589800b4

View file

@ -130,14 +130,6 @@ func (p *v2Puller) download(di *downloadInfo) {
blobs := p.repo.Blobs(context.Background()) 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) layerDownload, err := blobs.Open(context.Background(), di.digest)
if err != nil { if err != nil {
logrus.Debugf("Error fetching layer: %v", err) logrus.Debugf("Error fetching layer: %v", err)
@ -146,6 +138,21 @@ func (p *v2Puller) download(di *downloadInfo) {
} }
defer layerDownload.Close() 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) verifier, err := digest.NewDigestVerifier(di.digest)
if err != nil { if err != nil {
di.err <- err di.err <- err