From db557f647294238c9394744a874d92954464bb95 Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 23 Dec 2025 07:36:32 +0100 Subject: [PATCH 1/4] add header fields for PITR --- snapshot/header/header.go | 2 ++ 1 file changed, 2 insertions(+) diff --git a/snapshot/header/header.go b/snapshot/header/header.go index d40498794..4fd76c904 100644 --- a/snapshot/header/header.go +++ b/snapshot/header/header.go @@ -93,6 +93,8 @@ type Header struct { Tags []string `msgpack:"tags" json:"tags"` Context []KeyValue `msgpack:"context" json:"context"` Sources []Source `msgpack:"sources" json:"sources"` + Sequence uuid.UUID `msgpack:"sequence" json:"sequence"` + Parent objects.MAC `msgpack:"parent" json:"parent"` } func NewHeader(name string, identifier objects.MAC) *Header { From 299fb771c42c2406b444a9628a569b2089321a78 Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 23 Dec 2025 07:40:41 +0100 Subject: [PATCH 2/4] add locate for PITR fields --- locate/locate.go | 49 ++++++++++++++++++++++++++++++++++++++++----- locate/snapshots.go | 6 ++++++ 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/locate/locate.go b/locate/locate.go index 503c73bd6..72d63492f 100644 --- a/locate/locate.go +++ b/locate/locate.go @@ -7,6 +7,7 @@ import ( "time" "github.com/PlakarKorp/kloset/objects" + "github.com/google/uuid" ) type SortOrder int @@ -36,6 +37,8 @@ type ItemFilters struct { Types []string Origins []string Roots []string + Sequences []uuid.UUID + Parents []objects.MAC } func (it *ItemFilters) HasTag(tag string) bool { @@ -86,6 +89,30 @@ func (it ItemFilters) HasRoot(root string) bool { return false } +func (it ItemFilters) HasSequence(seq uuid.UUID) bool { + if seq == uuid.Nil { + return true + } + for _, t := range it.Sequences { + if t == seq { + return true + } + } + return false +} + +func (it ItemFilters) HasParent(parent objects.MAC) bool { + if parent == objects.NilMac { + return true + } + for _, t := range it.Parents { + if t == parent { + return true + } + } + return false +} + type Item struct { ItemID objects.MAC Timestamp time.Time @@ -113,11 +140,13 @@ type LocateFilters struct { Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` IgnoreTags []string `json:"ignore_tags,omitempty" yaml:"ignore_tags,omitempty"` - Latest bool `json:"latest,omitempty" yaml:"latest,omitempty"` // if true, consider only the latest matching item - IDs []string `json:"ids,omitempty" yaml:"ids,omitempty"` - Types []string `json:"types,omitempty" yaml:"types,omitempty"` - Origins []string `json:"origins,omitempty" yaml:"origins,omitempty"` - Roots []string `json:"roots,omitempty" yaml:"roots,omitempty"` + Latest bool `json:"latest,omitempty" yaml:"latest,omitempty"` // if true, consider only the latest matching item + IDs []string `json:"ids,omitempty" yaml:"ids,omitempty"` + Types []string `json:"types,omitempty" yaml:"types,omitempty"` + Origins []string `json:"origins,omitempty" yaml:"origins,omitempty"` + Roots []string `json:"roots,omitempty" yaml:"roots,omitempty"` + Sequences []uuid.UUID `json:"sequences,omitempty" yaml:"sequences,omitempty"` + Parents []objects.MAC `json:"parents,omitempty" yaml:"parents,omitempty"` } type LocatePeriods struct { @@ -283,6 +312,16 @@ func (lo *LocateOptions) Matches(it Item) bool { return false } } + for _, seq := range lo.Filters.Sequences { + if !it.Filters.HasSequence(seq) { + return false + } + } + for _, parent := range lo.Filters.Parents { + if !it.Filters.HasParent(parent) { + return false + } + } return true } diff --git a/locate/snapshots.go b/locate/snapshots.go index 039e67db1..8ddb54569 100644 --- a/locate/snapshots.go +++ b/locate/snapshots.go @@ -13,6 +13,7 @@ import ( "github.com/PlakarKorp/kloset/objects" "github.com/PlakarKorp/kloset/repository" "github.com/PlakarKorp/kloset/snapshot" + "github.com/google/uuid" ) // LocateSnapshotIDs preserves the legacy behavior using policy.FilterAndSort. @@ -93,10 +94,13 @@ func buildPolicyItems(repo *repository.Repository) []Item { roots := []string{} types := []string{} origins := []string{} + sequences := []uuid.UUID{} + parents := []objects.MAC{} for _, src := range h.Sources { roots = append(roots, src.Importer.Directory) types = append(types, src.Importer.Type) origins = append(origins, src.Importer.Origin) + } it := Item{ @@ -112,6 +116,8 @@ func buildPolicyItems(repo *repository.Repository) []Item { Types: types, Origins: origins, Roots: roots, + Sequences: sequences, + Parents: parents, }, } From 7ee1e663681795848d1e7fecb87fcb6aeda5783c Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 23 Dec 2025 07:48:54 +0100 Subject: [PATCH 3/4] make parent field prefix-search --- locate/install.go | 28 ++++++++++++++++++++++++++++ locate/locate.go | 22 +++++++++++----------- locate/snapshots.go | 2 +- 3 files changed, 40 insertions(+), 12 deletions(-) diff --git a/locate/install.go b/locate/install.go index acb6306d7..8a55c74c2 100644 --- a/locate/install.go +++ b/locate/install.go @@ -3,6 +3,8 @@ package locate import ( "flag" "strings" + + "github.com/google/uuid" ) func (po *LocateOptions) installGenericFlags(flags *flag.FlagSet) { @@ -41,6 +43,32 @@ func (po *LocateOptions) installGenericFlags(flags *flag.FlagSet) { } return nil }) + + flags.Func("parent", "filter by parent (repeat).", + func(v string) error { + for _, t := range strings.Split(v, ",") { + t = strings.TrimSpace(t) + if t != "" { + po.Filters.Roots = append(po.Filters.Roots, t) + } + } + return nil + }) + + flags.Func("seq", "filter by sequence (repeat).", + func(v string) error { + for _, t := range strings.Split(v, ",") { + t = strings.TrimSpace(t) + if t != "" { + seq, err := uuid.Parse(t) + if err != nil { + return err + } + po.Filters.Sequences = append(po.Filters.Sequences, seq) + } + } + return nil + }) } func (po *LocateOptions) InstallLocateFlags(flags *flag.FlagSet) { diff --git a/locate/locate.go b/locate/locate.go index 72d63492f..624331f9c 100644 --- a/locate/locate.go +++ b/locate/locate.go @@ -38,7 +38,7 @@ type ItemFilters struct { Origins []string Roots []string Sequences []uuid.UUID - Parents []objects.MAC + Parents []string } func (it *ItemFilters) HasTag(tag string) bool { @@ -101,12 +101,12 @@ func (it ItemFilters) HasSequence(seq uuid.UUID) bool { return false } -func (it ItemFilters) HasParent(parent objects.MAC) bool { - if parent == objects.NilMac { +func (it ItemFilters) HasParent(parent string) bool { + if parent == "" { return true } for _, t := range it.Parents { - if t == parent { + if strings.HasPrefix(t, parent) { return true } } @@ -140,13 +140,13 @@ type LocateFilters struct { Tags []string `json:"tags,omitempty" yaml:"tags,omitempty"` IgnoreTags []string `json:"ignore_tags,omitempty" yaml:"ignore_tags,omitempty"` - Latest bool `json:"latest,omitempty" yaml:"latest,omitempty"` // if true, consider only the latest matching item - IDs []string `json:"ids,omitempty" yaml:"ids,omitempty"` - Types []string `json:"types,omitempty" yaml:"types,omitempty"` - Origins []string `json:"origins,omitempty" yaml:"origins,omitempty"` - Roots []string `json:"roots,omitempty" yaml:"roots,omitempty"` - Sequences []uuid.UUID `json:"sequences,omitempty" yaml:"sequences,omitempty"` - Parents []objects.MAC `json:"parents,omitempty" yaml:"parents,omitempty"` + Latest bool `json:"latest,omitempty" yaml:"latest,omitempty"` // if true, consider only the latest matching item + IDs []string `json:"ids,omitempty" yaml:"ids,omitempty"` + Types []string `json:"types,omitempty" yaml:"types,omitempty"` + Origins []string `json:"origins,omitempty" yaml:"origins,omitempty"` + Roots []string `json:"roots,omitempty" yaml:"roots,omitempty"` + Sequences []uuid.UUID `json:"sequences,omitempty" yaml:"sequences,omitempty"` + Parents []string `json:"parents,omitempty" yaml:"parents,omitempty"` } type LocatePeriods struct { diff --git a/locate/snapshots.go b/locate/snapshots.go index 8ddb54569..fce9abd55 100644 --- a/locate/snapshots.go +++ b/locate/snapshots.go @@ -95,7 +95,7 @@ func buildPolicyItems(repo *repository.Repository) []Item { types := []string{} origins := []string{} sequences := []uuid.UUID{} - parents := []objects.MAC{} + parents := []string{} for _, src := range h.Sources { roots = append(roots, src.Importer.Directory) types = append(types, src.Importer.Type) From f0e28dfd254309f0b132ed4b1d2faf92633ea35a Mon Sep 17 00:00:00 2001 From: Gilles Chehade Date: Tue, 23 Dec 2025 08:15:12 +0100 Subject: [PATCH 4/4] fix locating of seq and parent --- locate/snapshots.go | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/locate/snapshots.go b/locate/snapshots.go index fce9abd55..f87d5f8be 100644 --- a/locate/snapshots.go +++ b/locate/snapshots.go @@ -100,7 +100,8 @@ func buildPolicyItems(repo *repository.Repository) []Item { roots = append(roots, src.Importer.Directory) types = append(types, src.Importer.Type) origins = append(origins, src.Importer.Origin) - + sequences = append(sequences, h.Sequence) + parents = append(parents, hex.EncodeToString(h.Parent[:])) } it := Item{