From b4b44dd0a8e3ec3084e8cbd897224f4d6b7de831 Mon Sep 17 00:00:00 2001 From: Armon Dadgar Date: Thu, 9 Oct 2014 17:22:09 -0700 Subject: [PATCH] command/remote: Refresh state before the disable --- command/remote.go | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/command/remote.go b/command/remote.go index 1ccb90cfd..4959d7aa2 100644 --- a/command/remote.go +++ b/command/remote.go @@ -98,24 +98,9 @@ func (c *RemoteCommand) Run(args []string) int { return 0 } -// pullState is used to refresh our state before disabling remote -// state management -func (c *RemoteCommand) pullState() error { - // TODO - return nil -} - // disableRemoteState is used to disable remote state management, // and move the state file into place. func (c *RemoteCommand) disableRemoteState() int { - // Ensure we have the latest state before disabling - if c.conf.pullOnDisable { - if err := c.pullState(); err != nil { - c.Ui.Error(fmt.Sprintf("%s", err)) - return 1 - } - } - // Get the local state local, _, err := remote.ReadLocalState() if err != nil { @@ -123,6 +108,24 @@ func (c *RemoteCommand) disableRemoteState() int { return 1 } + // Ensure we have the latest state before disabling + if c.conf.pullOnDisable { + change, err := remote.RefreshState(local.Remote) + if err != nil { + c.Ui.Error(fmt.Sprintf( + "Failed to refresh from remote state: %v", err)) + return 1 + } + + // Exit if we were unable to update + if !change.SuccessfulPull() { + c.Ui.Error(fmt.Sprintf("%s", change)) + return 1 + } else { + c.Ui.Output(fmt.Sprintf("%s", change)) + } + } + // Clear the remote management, and copy into place local.Remote = nil fh, err := os.Create(c.conf.statePath)