Update edge case bug in ds.UpdateHostDeviceMapping (#15454)

Found by @mna while working on #14779.

Sort of an edge case but the change is simple enough to fix it.
This commit is contained in:
Lucas Manuel Rodriguez 2023-12-05 18:25:11 -03:00 committed by GitHub
parent 57351011fa
commit 33ceb0ab9f
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -2862,14 +2862,14 @@ func (ds *Datastore) ReplaceHostDeviceMapping(ctx context.Context, hid uint, map
insPart = ` (?, ?, ?),`
)
// index the mappings by email and source, to quickly check which ones
// need to be deleted and inserted
toIns := make(map[string]*fleet.HostDeviceMapping)
for _, m := range mappings {
toIns[m.Email+"\n"+m.Source] = m
}
return ds.withRetryTxx(ctx, func(tx sqlx.ExtContext) error {
// index the mappings by email and source, to quickly check which ones
// need to be deleted and inserted
toIns := make(map[string]*fleet.HostDeviceMapping)
for _, m := range mappings {
toIns[m.Email+"\n"+m.Source] = m
}
var prevMappings []*fleet.HostDeviceMapping
if err := sqlx.SelectContext(ctx, tx, &prevMappings, selStmt, hid); err != nil {
return ctxerr.Wrap(ctx, err, "select previous host emails")