Download this file
| 1 | package hostguard |
| 2 | |
| 3 | import ( |
| 4 | "bytes" |
| 5 | "context" |
| 6 | ) |
| 7 | |
| 8 | // SettleRootInventory completes only the already persisted installation intent. |
| 9 | // The callback may finish its journal after independently proving its effects; |
| 10 | // it must not create effects or infer an intention from service state. |
| 11 | func (g Guard) SettleRootInventory(ctx context.Context, host string, intent []byte, settle func(RootInstallation) error) error { |
| 12 | if g.Root == nil || settle == nil { |
| 13 | return ErrInvalidInput |
| 14 | } |
| 15 | return g.readLocked(ctx, host, func(d *recordDir) error { |
| 16 | r, err := d.read(host) |
| 17 | if err != nil { |
| 18 | return err |
| 19 | } |
| 20 | if r.pendingInstallation == nil || !bytes.Equal(r.pendingInventory, intent) { |
| 21 | return ErrInvalidInput |
| 22 | } |
| 23 | in := *r.pendingInstallation |
| 24 | if r.installation.Incarnation != in.Incarnation || r.installation.Stamp != in.Stamp || r.installation.InventoryRevision+1 != in.InventoryRevision || r.ActiveStamp != in.Stamp { |
| 25 | return ErrRecordIncarnation |
| 26 | } |
| 27 | if err := settle(in); err != nil { |
| 28 | return err |
| 29 | } |
| 30 | r.installation = in |
| 31 | r.pendingInventory, r.pendingInstallation = nil, nil |
| 32 | return d.write(r) |
| 33 | }) |
| 34 | } |
| 35 | |