command/push: only add module directory to tar if it exists

This commit is contained in:
Mitchell Hashimoto 2016-08-23 23:19:02 -07:00
parent 92b15de080
commit 928fdff33e
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
1 changed files with 11 additions and 2 deletions

View File

@ -211,9 +211,18 @@ func (c *PushCommand) Run(args []string) int {
statePathKey := fmt.Sprintf("%s/%s", DefaultDataDir, DefaultStateFilename) statePathKey := fmt.Sprintf("%s/%s", DefaultDataDir, DefaultStateFilename)
archiveOpts.Extra[statePathKey] = filepath.Join(dataDirAbs, DefaultStateFilename) archiveOpts.Extra[statePathKey] = filepath.Join(dataDirAbs, DefaultStateFilename)
if moduleUpload { 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") 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 { } else {
// If we're not uploading modules, explicitly exclude add that // If we're not uploading modules, explicitly exclude add that
archiveOpts.Exclude = append( archiveOpts.Exclude = append(