Add Exists() helper to target

This commit is contained in:
Chris Roberts 2022-07-08 09:06:38 -07:00
parent e78d0b6681
commit 7c28aa3ce8

View File

@ -326,6 +326,15 @@ func (t *Target) DataDir() (*datadir.Target, error) {
return t.dir, nil
}
// Returns if the target exists based on state
func (t *Target) Exists() bool {
s, _ := t.State()
if s == core.NOT_CREATED || s == core.UNKNOWN {
return false
}
return true
}
func (t *Target) State() (state core.State, err error) {
switch t.target.State {
case vagrant_server.Operation_UNKNOWN:
@ -440,12 +449,11 @@ func (t *Target) Save() (err error) {
func (t *Target) Destroy() (err error) {
// Run all the cleanup tasks on the target
t.logger.Trace("destroying target")
t.Close()
t.m.Lock()
defer t.m.Unlock()
t.logger.Trace("destroying target")
// Delete the target from the database
_, err = t.Client().DeleteTarget(t.ctx, &vagrant_server.DeleteTargetRequest{
Target: t.Ref().(*vagrant_plugin_sdk.Ref_Target),