package hostguard import ( "bytes" "context" ) // SettleRootInventory completes only the already persisted installation intent. // The callback may finish its journal after independently proving its effects; // it must not create effects or infer an intention from service state. func (g Guard) SettleRootInventory(ctx context.Context, host string, intent []byte, settle func(RootInstallation) error) error { if g.Root == nil || settle == nil { return ErrInvalidInput } return g.readLocked(ctx, host, func(d *recordDir) error { r, err := d.read(host) if err != nil { return err } if r.pendingInstallation == nil || !bytes.Equal(r.pendingInventory, intent) { return ErrInvalidInput } in := *r.pendingInstallation if r.installation.Incarnation != in.Incarnation || r.installation.Stamp != in.Stamp || r.installation.InventoryRevision+1 != in.InventoryRevision || r.ActiveStamp != in.Stamp { return ErrRecordIncarnation } if err := settle(in); err != nil { return err } r.installation = in r.pendingInventory, r.pendingInstallation = nil, nil return d.write(r) }) }