From 928fdff33e280428a8c0c0662bfd43c1e2d2c82a Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Tue, 23 Aug 2016 23:19:02 -0700 Subject: [PATCH] command/push: only add module directory to tar if it exists --- command/push.go | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) diff --git a/command/push.go b/command/push.go index 67f8815222..84ff5afb59 100644 --- a/command/push.go +++ b/command/push.go @@ -211,9 +211,18 @@ func (c *PushCommand) Run(args []string) int { statePathKey := fmt.Sprintf("%s/%s", DefaultDataDir, DefaultStateFilename) archiveOpts.Extra[statePathKey] = filepath.Join(dataDirAbs, DefaultStateFilename) if moduleUpload { - // If we're uploading modules, explicitly add that + // If we're uploading modules, explicitly add that directory if exists. moduleKey := fmt.Sprintf("%s/%s", DefaultDataDir, "modules") - archiveOpts.Extra[moduleKey] = filepath.Join(dataDirAbs, "modules") + moduleDir := filepath.Join(dataDirAbs, "modules") + _, err := os.Stat(moduleDir) + if err == nil { + archiveOpts.Extra[moduleKey] = filepath.Join(dataDirAbs, "modules") + } + if err != nil && !os.IsNotExist(err) { + c.Ui.Error(fmt.Sprintf( + "Error checking for module dir %q: %s", moduleDir, err)) + return 1 + } } else { // If we're not uploading modules, explicitly exclude add that archiveOpts.Exclude = append(