Don't create empty backups

Not really a problem, but created unnecessary files and changes existing
behavior.
pull/11187/head
James Bardin 9 years ago
parent 1646310e68
commit 7590154974

@ -1,8 +1,6 @@
package state
import (
"github.com/hashicorp/terraform/terraform"
)
import "github.com/hashicorp/terraform/terraform"
// BackupState wraps a State that backs up the state on the first time that
// a WriteState or PersistState is called.
@ -68,9 +66,14 @@ func (s *BackupState) backup() error {
state = s.Real.State()
}
ls := &LocalState{Path: s.Path}
if err := ls.WriteState(state); err != nil {
return err
// LocalState.WriteState ensures that a file always exists for locking
// purposes, but we don't need a backup or lock if the state is empty, so
// skip this with a nil state.
if state != nil {
ls := &LocalState{Path: s.Path}
if err := ls.WriteState(state); err != nil {
return err
}
}
s.done = true

Loading…
Cancel
Save