package host import ( "context" "github.com/carlosframework/platform/internal/hostbox" "github.com/carlosframework/platform/internal/hostguard" "github.com/carlosframework/platform/internal/rootstate" "path/filepath" ) func (h ClaimRootHTTP) bindInventoryPaths(ctx context.Context, in *hostbox.StopInventory) error { if h.inventoryIdentity == nil { return nil } prior, _, err := h.Journals.Inventory.Snapshot(ctx, in.Host, hostguard.Captured{Incarnation: in.Incarnation, Stamp: in.InstallationStamp}) if err != nil { return err } for i, e := range in.Entries { // Caller-supplied persistent evidence never creates root authority. claimedBoot := e.Identity.Boot e.Identity = rootstate.FileIdentity{} if e.Kind != "path" || e.Materialization != "materialized" { in.Entries[i] = e continue } if e.ManagedRoot != "data" || !filepath.IsLocal(e.RelativePath) { return hostbox.ErrTypedInventory } oldFound := false for _, old := range prior.Entries { if old.ArtifactID == e.ArtifactID && old.Materialization == "materialized" { if old.Identity.Boot == "" { return hostbox.ErrTypedInventory } e.Identity = old.Identity oldFound = true } } path := filepath.Join(h.Roots[e.ManagedRoot], e.RelativePath) f, err := hostbox.OpenInventoryFile(path) if err != nil { return err } if oldFound { err = hostbox.VerifyInventoryIdentity(h.Roots[e.ManagedRoot], e) } else { e.Identity, err = h.inventoryIdentity(f) if err == nil && (claimedBoot != e.Identity.Boot || e.Device != e.Identity.Device || e.Inode != e.Identity.Inode || e.Type != e.Identity.Mode&0170000) { err = hostbox.ErrChanged } } f.Close() if err != nil { return err } in.Entries[i] = e } return nil }