package release import ( "errors" "os" ) // RecordCreation is called only inside root's first-registration transaction, // after root proves the installation is new. Existing history is preserved. func (h *RootHistory) RecordCreation(b HistoryBinding, installation string) error { if !b.valid() || installation == "" || len(installation) > 4096 { return os.ErrPermission } _, err := h.read(b) if err == nil { return nil } if !errors.Is(err, os.ErrNotExist) { return err } return h.write(historyRecord{Schema: 1, Binding: b, Revision: 1, Creation: installation, Fresh: true, Programs: historyPrograms{Revision: 1, Complete: true}, Refusals: historyRefusals{Revision: 1, Complete: true}}) } func (h *RootHistory) FreshInstallation(b HistoryBinding, installation string) (bool, error) { r, err := h.read(b) if err != nil { return false, err } return installation != "" && r.Creation == installation && r.Fresh, nil } func (h *RootHistory) ConsumeCreation(b HistoryBinding) error { r, err := h.read(b) if errors.Is(err, os.ErrNotExist) { return nil } if err != nil { return err } if !r.Fresh { return nil } if r.Revision == ^uint64(0) { return os.ErrPermission } r.Revision++ r.Fresh = false return h.write(r) }