From 9a8209cfbd3a9e9d8c84dfc10039c4f5d054bc3a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 24 Aug 2016 10:39:50 -0700 Subject: [PATCH] command/push: create the proper parent directory entries in tar --- command/push.go | 6 ++-- command/push_test.go | 1 + .../hashicorp/atlas-go/archive/archive.go | 28 +++++++++++++++++++ vendor/vendor.json | 4 ++- 4 files changed, 36 insertions(+), 3 deletions(-) diff --git a/command/push.go b/command/push.go index 84ff5afb59..db2ae3db43 100644 --- a/command/push.go +++ b/command/push.go @@ -203,8 +203,10 @@ func (c *PushCommand) Run(args []string) int { // Build the archiving options, which includes everything it can // by default according to VCS rules but forcing the data directory. archiveOpts := &archive.ArchiveOpts{ - VCS: archiveVCS, - Extra: make(map[string]string), + VCS: archiveVCS, + Extra: map[string]string{ + DefaultDataDir: archive.ExtraEntryDir, + }, } // Always store the state file in here so we can find state diff --git a/command/push_test.go b/command/push_test.go index 7f8d70d0d1..2fdbf2f268 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -117,6 +117,7 @@ func TestPush_noUploadModules(t *testing.T) { actual := testArchiveStr(t, archivePath) expected := []string{ + ".terraform/", ".terraform/terraform.tfstate", "child/", "child/main.tf", diff --git a/vendor/github.com/hashicorp/atlas-go/archive/archive.go b/vendor/github.com/hashicorp/atlas-go/archive/archive.go index d9232b4f0e..0a025b21f7 100644 --- a/vendor/github.com/hashicorp/atlas-go/archive/archive.go +++ b/vendor/github.com/hashicorp/atlas-go/archive/archive.go @@ -50,6 +50,12 @@ func (o *ArchiveOpts) IsSet() bool { return len(o.Exclude) > 0 || len(o.Include) > 0 || o.VCS } +// Constants related to setting special values for Extra in ArchiveOpts. +const ( + // ExtraEntryDir just creates the Extra key as a directory entry. + ExtraEntryDir = "" +) + // CreateArchive takes the given path and ArchiveOpts and archives it. // // The archive will be fully completed and put into a temporary file. @@ -419,7 +425,29 @@ func copyConcreteEntry( } func copyExtras(w *tar.Writer, extra map[string]string) error { + var tmpDir string + defer func() { + if tmpDir != "" { + os.RemoveAll(tmpDir) + } + }() + for entry, path := range extra { + // If the path is empty, then we set it to a generic empty directory + if path == "" { + // If tmpDir is still empty, then we create an empty dir + if tmpDir == "" { + td, err := ioutil.TempDir("", "archive") + if err != nil { + return err + } + + tmpDir = td + } + + path = tmpDir + } + info, err := os.Stat(path) if err != nil { return err diff --git a/vendor/vendor.json b/vendor/vendor.json index f1401fc404..78227755a9 100644 --- a/vendor/vendor.json +++ b/vendor/vendor.json @@ -1083,9 +1083,11 @@ "revision": "c0cf0cb802adad24252ce1307c4c896edd566870" }, { + "checksumSHA1": "FUiF2WLrih0JdHsUTMMDz3DRokw=", "comment": "20141209094003-92-g95fa852", "path": "github.com/hashicorp/atlas-go/archive", - "revision": "95fa852edca41c06c4ce526af4bb7dec4eaad434" + "revision": "8e45a6c8b2de014db767a42c3ee777f101e11624", + "revisionTime": "2016-08-24T17:34:10Z" }, { "checksumSHA1": "yylO3hSRKd0T4mveT9ho2OSARwU=",