command/push: create the proper parent directory entries in tar

This commit is contained in:
Mitchell Hashimoto 2016-08-24 10:39:50 -07:00
parent 928fdff33e
commit 9a8209cfbd
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
4 changed files with 36 additions and 3 deletions

View File

@ -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

View File

@ -117,6 +117,7 @@ func TestPush_noUploadModules(t *testing.T) {
actual := testArchiveStr(t, archivePath)
expected := []string{
".terraform/",
".terraform/terraform.tfstate",
"child/",
"child/main.tf",

View File

@ -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

4
vendor/vendor.json vendored
View File

@ -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=",