From 36bd5d6480617549abd2e96d82e669de486aca5f Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Tue, 18 Sep 2018 20:32:04 +0200 Subject: [PATCH] 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. --- command/taint.go | 9 +++++---- command/untaint.go | 9 +++++---- 2 files changed, 10 insertions(+), 8 deletions(-) diff --git a/command/taint.go b/command/taint.go index 4dc16e60cd..4e0ea6a699 100644 --- a/command/taint.go +++ b/command/taint.go @@ -77,10 +77,6 @@ func (c *TaintCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) return 1 } - if err := st.RefreshState(); err != nil { - c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) - return 1 - } if c.stateLock { 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) } + if err := st.RefreshState(); err != nil { + c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) + return 1 + } + // Get the actual state structure s := st.State() if s.Empty() { diff --git a/command/untaint.go b/command/untaint.go index 39d047fd67..cc6923f089 100644 --- a/command/untaint.go +++ b/command/untaint.go @@ -65,10 +65,6 @@ func (c *UntaintCommand) Run(args []string) int { c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) return 1 } - if err := st.RefreshState(); err != nil { - c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) - return 1 - } if c.stateLock { 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) } + if err := st.RefreshState(); err != nil { + c.Ui.Error(fmt.Sprintf("Failed to load state: %s", err)) + return 1 + } + // Get the actual state structure s := st.State() if s.Empty() {