From e58ee0967a1995ad0aa330efd6cbc7e369c4b4bc Mon Sep 17 00:00:00 2001 From: Don McCasland Date: Thu, 26 Sep 2019 11:29:53 -0700 Subject: [PATCH] Fixing logic for Copy command. The problem was not that tar files were being unpacked in wrong order. The problem was that the COPY command requires the FS to be unpacked before it does its work. --- pkg/commands/copy.go | 6 ++++++ pkg/util/fs_util.go | 4 ++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/pkg/commands/copy.go b/pkg/commands/copy.go index c8ec11427..1f62b4311 100644 --- a/pkg/commands/copy.go +++ b/pkg/commands/copy.go @@ -70,6 +70,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu // we need to add '/' to the end to indicate the destination is a directory dest = filepath.Join(cwd, dest) + "/" } + logrus.Debugf("Calling CopyDir fullPath:%s dest:%s", fullPath, dest) copiedFiles, err := util.CopyDir(fullPath, dest, c.buildcontext) if err != nil { return err @@ -87,6 +88,7 @@ func (c *CopyCommand) ExecuteCommand(config *v1.Config, buildArgs *dockerfile.Bu c.snapshotFiles = append(c.snapshotFiles, destPath) } else { // ... Else, we want to copy over a file + logrus.Debugf("Calling CopyFile fullPath:%s destPath:%s", fullPath, destPath) exclude, err := util.CopyFile(fullPath, destPath, c.buildcontext) if err != nil { return err @@ -134,3 +136,7 @@ func (c *CopyCommand) FilesUsedFromContext(config *v1.Config, buildArgs *dockerf func (c *CopyCommand) MetadataOnly() bool { return false } + +func (c *CopyCommand) RequiresUnpackedFS() bool { + return true +} diff --git a/pkg/util/fs_util.go b/pkg/util/fs_util.go index b9dffacc4..a4d7996f8 100644 --- a/pkg/util/fs_util.go +++ b/pkg/util/fs_util.go @@ -192,8 +192,8 @@ func extractFile(dest string, hdr *tar.Header, tr io.Reader) error { // or a file was copied over a directory prior to now fi, err := os.Stat(dir) if os.IsNotExist(err) || !fi.IsDir() { - logrus.Debugf("base %s for file %s does not exist. Creating.", base, path) - os.RemoveAll(dir) + logrus.Infof("base %s for file %s does not exist. Creating.", base, path) + //os.RemoveAll(dir) if err := os.MkdirAll(dir, 0755); err != nil { return err }