Make sure the state is locked before it is used

Both the `taint` and `untaint` commands had a small logical error that caused them you first get the state and then lock it.
This commit is contained in:
Sander van Harmelen 2018-09-18 20:32:04 +02:00
parent 813b5fd27f
commit 36bd5d6480
2 changed files with 10 additions and 8 deletions

View File

@ -77,10 +77,6 @@ func (c *TaintCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1 return 1
} }
if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}
if c.stateLock { if c.stateLock {
stateLocker := clistate.NewLocker(context.Background(), c.stateLockTimeout, c.Ui, c.Colorize()) stateLocker := clistate.NewLocker(context.Background(), c.stateLockTimeout, c.Ui, c.Colorize())
@ -91,6 +87,11 @@ func (c *TaintCommand) Run(args []string) int {
defer stateLocker.Unlock(nil) defer stateLocker.Unlock(nil)
} }
if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}
// Get the actual state structure // Get the actual state structure
s := st.State() s := st.State()
if s.Empty() { if s.Empty() {

View File

@ -65,10 +65,6 @@ func (c *UntaintCommand) Run(args []string) int {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1 return 1
} }
if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}
if c.stateLock { if c.stateLock {
stateLocker := clistate.NewLocker(context.Background(), c.stateLockTimeout, c.Ui, c.Colorize()) stateLocker := clistate.NewLocker(context.Background(), c.stateLockTimeout, c.Ui, c.Colorize())
@ -79,6 +75,11 @@ func (c *UntaintCommand) Run(args []string) int {
defer stateLocker.Unlock(nil) defer stateLocker.Unlock(nil)
} }
if err := st.RefreshState(); err != nil {
c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err))
return 1
}
// Get the actual state structure // Get the actual state structure
s := st.State() s := st.State()
if s.Empty() { if s.Empty() {