backend/remote-state/gcloud: Refactor Backend.DeleteState().

Fixes:
* https://github.com/golang/go/wiki/CodeReviewComments#doc-comments
* https://github.com/golang/go/wiki/CodeReviewComments#error-strings
This commit is contained in:
Florian Forster 2017-09-08 09:30:48 +02:00 committed by James Bardin
parent fabba5c0c8
commit 9ae45e320f
1 changed files with 5 additions and 9 deletions

View File

@ -49,22 +49,18 @@ func (b *Backend) States() ([]string, error) {
return states, nil
}
// DeleteState deletes the named state. The "default" state cannot be deleted.
func (b *Backend) DeleteState(name string) error {
if name == backend.DefaultStateName || name == "" {
return fmt.Errorf("Can't delete default state")
if name == backend.DefaultStateName {
return fmt.Errorf("cowardly refusing to delete the %q state", name)
}
client, err := b.remoteClient(name)
if err != nil {
return fmt.Errorf("Failed to create Google Storage client: %v", err)
return err
}
err = client.Delete()
if err != nil {
return fmt.Errorf("Failed to delete state file %v: %v", client.stateFileURL(), err)
}
return nil
return client.Delete()
}
// get a remote client configured for this state