From 1ea9413c07209b98ec8c5011ce7a2907c4771c87 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 22 Feb 2017 13:11:26 -0500 Subject: [PATCH] Remove state path handling from commands The Local backend is now responsible for handling the paths to the local state files, since they are dependent on the current environment. --- command/meta_backend.go | 24 +++--------------------- command/state_meta.go | 6 +++++- 2 files changed, 8 insertions(+), 22 deletions(-) diff --git a/command/meta_backend.go b/command/meta_backend.go index 86d7aaf7b..629fc9642 100644 --- a/command/meta_backend.go +++ b/command/meta_backend.go @@ -72,24 +72,6 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, error) { opts = &BackendOpts{} } - // Setup the local state paths - statePath := m.statePath - stateOutPath := m.stateOutPath - backupPath := m.backupPath - if statePath == "" { - statePath = DefaultStateFilename - } - if stateOutPath == "" { - stateOutPath = statePath - } - if backupPath == "" { - backupPath = stateOutPath + DefaultBackupExtension - } - if backupPath == "-" { - // The local backend expects an empty string for not taking backups. - backupPath = "" - } - // Initialize a backend from the config unless we're forcing a purely // local operation. var b backend.Backend @@ -114,9 +96,9 @@ func (m *Meta) Backend(opts *BackendOpts) (backend.Enhanced, error) { cliOpts := &backend.CLIOpts{ CLI: m.Ui, CLIColor: m.Colorize(), - StatePath: statePath, - StateOutPath: stateOutPath, - StateBackupPath: backupPath, + StatePath: m.statePath, + StateOutPath: m.stateOutPath, + StateBackupPath: m.backupPath, ContextOpts: m.contextOpts(), Input: m.Input(), Validation: true, diff --git a/command/state_meta.go b/command/state_meta.go index 9155d0f95..eccfba447 100644 --- a/command/state_meta.go +++ b/command/state_meta.go @@ -36,12 +36,16 @@ func (c *StateMeta) State(m *Meta) (state.State, error) { panic(err) } localB := localRaw.(*backendlocal.Local) + _, stateOutPath, _, err := localB.StatePaths() + if err != nil { + return nil, err + } // Determine the backup path. stateOutPath is set to the resulting // file where state is written (cached in the case of remote state) backupPath := fmt.Sprintf( "%s.%d%s", - localB.StateOutPath, + stateOutPath, time.Now().UTC().Unix(), DefaultBackupExtension)