From b630043f7198b12dc7e56d8de8d63a8331700746 Mon Sep 17 00:00:00 2001 From: Alex Aizman Date: Thu, 27 Jun 2024 13:33:37 -0400 Subject: [PATCH] list-objects: sort virtual dirs first, objects second * part four, prev. commit: da0606fa17eec Signed-off-by: Alex Aizman --- cmn/objlist_utils.go | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/cmn/objlist_utils.go b/cmn/objlist_utils.go index 5fd5fc978ee..72af7545f5d 100644 --- a/cmn/objlist_utils.go +++ b/cmn/objlist_utils.go @@ -21,16 +21,23 @@ var nilEntry LsoEnt // LsoEntries // //////////////// -func (entries LsoEntries) cmp(i, j int) bool { return entries[i].less(entries[j]) } +func (entries LsoEntries) cmp(i, j int) bool { + eni, enj := entries[i], entries[j] + return eni.less(enj) +} func appSorted(entries LsoEntries, ne *LsoEnt) LsoEntries { - for i := range entries { - if ne.Name > entries[i].Name { + for i, eni := range entries { + if eni.IsDir() != ne.IsDir() { + if eni.IsDir() { + continue + } + } else if ne.Name > eni.Name { continue } // dedup - if ne.Name == entries[i].Name { - if ne.Status() < entries[i].Status() { + if ne.Name == eni.Name { + if ne.Status() < eni.Status() { entries[i] = ne } return entries @@ -74,6 +81,15 @@ func (be *LsoEnt) IsListedArch() bool { return be.Flags&apc.EntryIsArchive != 0 func (be *LsoEnt) String() string { return "{" + be.Name + "}" } func (be *LsoEnt) less(oe *LsoEnt) bool { + if be.IsDir() { + if oe.IsDir() { + return be.Name < oe.Name + } + return true + } + if oe.IsDir() { + return false + } if be.Name == oe.Name { return be.Status() < oe.Status() } @@ -187,8 +203,6 @@ func MergeLso(lists []*LsoRes, lsmsg *apc.LsoMsg, maxSize int) *LsoRes { resList.Entries = resList.Entries[:0] resList.ContinuationToken = token - // TODO -- FIXME: sort virtual dirs separately ===================== - for _, entry := range tmp { resList.Entries = appSorted(resList.Entries, entry) }