Search for project and target before upserting
This commit is contained in:
parent
a5f0064a86
commit
eeafbe4954
@ -148,9 +148,7 @@ func (s *State) projectPut(
|
||||
s.log.Trace("storing project", "project", value, "basis", value.Basis)
|
||||
|
||||
// Grab the stored project if it's available
|
||||
existProject, err := s.projectGet(dbTxn, memTxn, &vagrant_plugin_sdk.Ref_Project{
|
||||
ResourceId: value.ResourceId,
|
||||
})
|
||||
existProject, err := s.projectFind(dbTxn, memTxn, value)
|
||||
if err != nil {
|
||||
// ensure value is nil to identify non-existence
|
||||
existProject = nil
|
||||
|
||||
@ -170,12 +170,23 @@ func (s *State) targetPut(
|
||||
}
|
||||
|
||||
if value.ResourceId == "" {
|
||||
s.log.Trace("target has no resource id, assuming new target",
|
||||
"target", value)
|
||||
if value.ResourceId, err = s.newResourceId(); err != nil {
|
||||
s.log.Error("failed to create resource id for target", "target", value,
|
||||
"error", err)
|
||||
return
|
||||
// If no resource id is provided, try to find the target based on the name and project
|
||||
foundTarget, erro := s.targetFind(dbTxn, memTxn, value)
|
||||
// If an invalid return code is returned from find then an error occured
|
||||
if _, ok := status.FromError(erro); !ok {
|
||||
return erro
|
||||
}
|
||||
if foundTarget != nil {
|
||||
value.ResourceId = foundTarget.ResourceId
|
||||
value.Uuid = foundTarget.Uuid
|
||||
} else {
|
||||
s.log.Trace("target has no resource id and could not find matching target, assuming new target",
|
||||
"target", value)
|
||||
if value.ResourceId, err = s.newResourceId(); err != nil {
|
||||
s.log.Error("failed to create resource id for target", "target", value,
|
||||
"error", err)
|
||||
return
|
||||
}
|
||||
}
|
||||
if value.Uuid == "" {
|
||||
s.log.Trace("target has no uuid assigned, assigning...", "target", value)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user