From 0fd9c98de3fc2c8fb1da6dc3ef277b3325106b26 Mon Sep 17 00:00:00 2001 From: "Guillaume J. Charmes" Date: Wed, 8 Jan 2014 14:20:50 -0800 Subject: [PATCH] Make sure the remote ADD are cached properly Docker-DCO-1.0-Signed-off-by: Guillaume J. Charmes (github: creack) --- buildfile.go | 18 +++++++++++++++--- 1 file changed, 15 insertions(+), 3 deletions(-) diff --git a/buildfile.go b/buildfile.go index 2243962f9e..de03e5879f 100644 --- a/buildfile.go +++ b/buildfile.go @@ -353,8 +353,9 @@ func (b *buildFile) CmdAdd(args string) error { // FIXME: do we really need this? var ( - origPath = orig - destPath = dest + origPath = orig + destPath = dest + remoteHash string ) if utils.IsURL(orig) { @@ -373,11 +374,20 @@ func (b *buildFile) CmdAdd(args string) error { } defer os.RemoveAll(tmpDirName) if _, err = io.Copy(tmpFile, resp.Body); err != nil { + tmpFile.Close() return err } origPath = path.Join(filepath.Base(tmpDirName), filepath.Base(tmpFileName)) tmpFile.Close() + // Process the checksum + r, err := archive.Tar(tmpFileName, archive.Uncompressed) + if err != nil { + return err + } + tarSum := utils.TarSum{Reader: r, DisableCompression: true} + remoteHash = tarSum.Sum(nil) + // If the destination is a directory, figure out the filename. if strings.HasSuffix(dest, "/") { u, err := url.Parse(orig) @@ -408,7 +418,9 @@ func (b *buildFile) CmdAdd(args string) error { sums = b.context.GetSums() ) - if fi, err := os.Stat(path.Join(b.contextPath, origPath)); err != nil { + if remoteHash != "" { + hash = remoteHash + } else if fi, err := os.Stat(path.Join(b.contextPath, origPath)); err != nil { return err } else if fi.IsDir() { var subfiles []string