package resolution import ( "fmt" "strings" mcat "git.novox.be/novox/mesh-sdk/go/catalogue" ) // derivedContributions is what a module's data section gives the backup holder: its backup lines and // its items. Every item is listed, so a valuable one on a machine is measured whether or not it is // copied; a cache is listed and not measured. func manifestDerivedContributions(m mcat.Manifest) []mcat.SeatContribution { items := m.DataItems() if len(items) == 0 { return nil } var lines []string kept := map[string]bool{} keep := func(path string) { if !kept[path] { kept[path] = true lines = append(lines, "path "+path) } } for _, it := range items { if !it.BackedUp() { continue } if it.Backup.IsDump() { lines = append(lines, "run "+strings.TrimSpace(it.Backup.Dump)) if into, ok := m.DataItem(it.Backup.Into); ok { keep(into.Path) } continue } keep(it.Path) } var described []string for _, it := range items { covered := "-" switch { case it.Backup.IsDump(): if into, ok := m.DataItem(it.Backup.Into); ok { covered = into.Path } case it.BackedUp(): covered = it.Path } described = append(described, fmt.Sprintf("item %s %s %s %s %s %s", it.ID, it.Class, it.Path, covered, it.Protection(), it.MeasuredBy())) } var out []mcat.SeatContribution if len(lines) > 0 { out = append(out, mcat.SeatContribution{Seat: mcat.BackupSeat, Kind: mcat.BackupKindBackup, Content: strings.Join(lines, "\n") + "\n"}) } return append(out, mcat.SeatContribution{Seat: mcat.BackupSeat, Kind: mcat.BackupKindData, Content: strings.Join(described, "\n") + "\n"}) } // allContributions is every contribution a module makes to a seat's holder: what it wrote, and what // its data section derives. **One list**: a module that declares its data has its backup lines // composed from it, and a backup line it still writes by hand is not placed — the catalogue check // refuses it — so the holder never copies two lists that disagree. func manifestAllContributions(m mcat.Manifest) []mcat.SeatContribution { if m.Data == nil { return m.Contributions } derived := manifestDerivedContributions(m) out := make([]mcat.SeatContribution, 0, len(m.Contributions)+len(derived)) for _, c := range m.Contributions { if s, known := mcat.SeatNamed(c.Seat); known && s.Name == mcat.BackupSeat { continue } out = append(out, c) } return append(out, derived...) }