From e636df8d9637514e125afe7418a3b98e5270858f Mon Sep 17 00:00:00 2001 From: Josh Hawn Date: Thu, 29 Jan 2015 10:57:30 -0800 Subject: [PATCH] No longer compute checksum when installing images. While checksums are verified when a layer is pulled from v2 registries, there are known issues where the checksum may change when the layer diff is computed again. To avoid these issues, the checksum should no longer be computed and stored until after it has been extracted to the docker storage driver. The checksums are instead computed lazily before they are pushed to a v2 registry. Docker-DCO-1.1-Signed-off-by: Josh Hawn (github: jlhawn) --- image/image.go | 42 ++++-------------------------------------- 1 file changed, 4 insertions(+), 38 deletions(-) diff --git a/image/image.go b/image/image.go index a4839e98fb..2187653b03 100644 --- a/image/image.go +++ b/image/image.go @@ -10,7 +10,6 @@ import ( "time" "github.com/docker/docker/pkg/archive" - "github.com/docker/docker/pkg/tarsum" "github.com/docker/docker/runconfig" "github.com/docker/docker/utils" ) @@ -80,48 +79,15 @@ func LoadImage(root string) (*Image, error) { // StoreImage stores file system layer data for the given image to the // image's registered storage driver. Image metadata is stored in a file -// at the specified root directory. This function also computes a checksum -// of `layerData` if the image does not have one already. -func StoreImage(img *Image, layerData archive.ArchiveReader, root string) error { - // Store the layer - var ( - size int64 - err error - driver = img.graph.Driver() - layerTarSum tarsum.TarSum - ) - - // If layerData is not nil, unpack it into the new layer +// at the specified root directory. +func StoreImage(img *Image, layerData archive.ArchiveReader, root string) (err error) { + // Store the layer. If layerData is not nil, unpack it into the new layer if layerData != nil { - // If the image doesn't have a checksum, we should add it. The layer - // checksums are verified when they are pulled from a remote, but when - // a container is committed it should be added here. Also ensure that - // the stored checksum has the latest version of tarsum (assuming we - // are using tarsum). - if tarsum.VersionLabelForChecksum(img.Checksum) != tarsum.Version1.String() { - // Either there was no checksum or it's not a tarsum.v1 - layerDataDecompressed, err := archive.DecompressStream(layerData) - if err != nil { - return err - } - defer layerDataDecompressed.Close() - - if layerTarSum, err = tarsum.NewTarSum(layerDataDecompressed, true, tarsum.Version1); err != nil { - return err - } - - if size, err = driver.ApplyDiff(img.ID, img.Parent, layerTarSum); err != nil { - return err - } - - img.Checksum = layerTarSum.Sum(nil) - } else if size, err = driver.ApplyDiff(img.ID, img.Parent, layerData); err != nil { + if img.Size, err = img.graph.Driver().ApplyDiff(img.ID, img.Parent, layerData); err != nil { return err } - } - img.Size = size if err := img.SaveSize(root); err != nil { return err }