From fdb0f0324f5c859d3b9baab3bd9e559628425641 Mon Sep 17 00:00:00 2001 From: Alejandro Mery Date: Tue, 22 Aug 2023 21:29:12 +0000 Subject: [PATCH] zones: finish scan sorting the content Signed-off-by: Alejandro Mery --- pkg/zones/scan.go | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/pkg/zones/scan.go b/pkg/zones/scan.go index e051df4..6c40b2f 100644 --- a/pkg/zones/scan.go +++ b/pkg/zones/scan.go @@ -2,6 +2,7 @@ package zones import ( "io/fs" + "sort" ) func (m *Zones) scan() error { @@ -9,6 +10,7 @@ func (m *Zones) scan() error { m.scanDirectory, m.scanMachines, m.scanZoneIDs, + m.scanSort, } { if err := fn(); err != nil { return err @@ -82,6 +84,37 @@ func (m *Zones) scanZoneIDs() error { return nil } +func (m *Zones) scanSort() error { + sort.SliceStable(m.Zones, func(i, j int) bool { + id1 := m.Zones[i].ID + id2 := m.Zones[j].ID + return id1 < id2 + }) + + m.ForEachZone(func(z *Zone) bool { + sort.SliceStable(z.Machines, func(i, j int) bool { + id1 := z.Machines[i].ID() + id2 := z.Machines[j].ID() + return id1 < id2 + }) + + return false + }) + + m.ForEachMachine(func(p *Machine) bool { + sort.SliceStable(p.RingAddresses, func(i, j int) bool { + ri1 := p.RingAddresses[i] + ri2 := p.RingAddresses[j] + + return ri1.Ring < ri2.Ring + }) + + return false + }) + + return nil +} + func (z *Zone) scan() error { // each directory is a machine entries, err := fs.ReadDir(z.zones.dir, z.Name)