command/remote: Refresh state before the disable

This commit is contained in:
Armon Dadgar 2014-10-09 17:22:09 -07:00 committed by Mitchell Hashimoto
parent 6e7cffd60b
commit b4b44dd0a8
1 changed files with 18 additions and 15 deletions

View File

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