carlos / platform Public

Clone
git clone https://amadan.net/carlos/platform

Plain git — no account needed to clone.

Download

Download this file

1package hostbox
2
3import "strings"
4
5func retirementWithTimers(in RetirementInventory, timers []Artifact, requireInventory bool) (RetirementInventory, error) {
6 in.Artifacts = append([]Artifact(nil), in.Artifacts...)
7 for _, timer := range timers {
8 found := false
9 for _, retained := range in.Artifacts {
10 if retained.Kind != ArtifactTimer || retained.Name != timer.Name {
11 continue
12 }
13 row, registration, combined := strings.Cut(timer.RowID, "~")
14 if !combined {
15 row, registration = timer.RowID, timer.RowID
16 }
17 if retained.Root != timer.Root || retained.Owner != timer.Owner || retained.RowID != row || row != registration || timer.Dev != 0 || timer.Ino != 0 || timer.Type != 0 {
18 return RetirementInventory{}, ErrTypedInventory
19 }
20 found = true
21 }
22 if !found {
23 if requireInventory {
24 return RetirementInventory{}, ErrTypedInventory
25 }
26 in.Artifacts = append(in.Artifacts, timer)
27 }
28 }
29 return in, nil
30}
31