[lxc-devel] [lxd/master] shared/simplestreams: Fix inconsistent sorting
stgraber on Github
lxc-bot at linuxcontainers.org
Sat Jan 25 15:36:56 UTC 2020
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 354 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20200125/30b62361/attachment.bin>
-------------- next part --------------
From 433f0ca1c15174a28cd18492802ae7073142d124 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Sat, 25 Jan 2020 17:36:20 +0200
Subject: [PATCH] shared/simplestreams: Fix inconsistent sorting
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
shared/simplestreams/sort.go | 48 +++++++++++++++++++++++++-----------
1 file changed, 34 insertions(+), 14 deletions(-)
diff --git a/shared/simplestreams/sort.go b/shared/simplestreams/sort.go
index 51babcd62a..3883dbe690 100644
--- a/shared/simplestreams/sort.go
+++ b/shared/simplestreams/sort.go
@@ -75,29 +75,49 @@ func (a sortedAliases) Swap(i, j int) {
}
func (a sortedAliases) Less(i, j int) bool {
- if nativeName == a[i].Architecture {
- return true
+ // Check functions.
+ isNative := func(arch string) bool {
+ return nativeName == arch
}
- archID, err := osarch.ArchitectureId(nativeName)
- if err != nil {
+ isPersonality := func(arch string) bool {
+ archID, err := osarch.ArchitectureId(nativeName)
+ if err != nil {
+ return false
+ }
+
+ personalities, err := osarch.ArchitecturePersonalities(archID)
+ if err != nil {
+ return false
+ }
+
+ for _, personality := range personalities {
+ personalityName, err := osarch.ArchitectureName(personality)
+ if err != nil {
+ return false
+ }
+
+ if personalityName == arch {
+ return true
+ }
+ }
+
return false
}
- personalities, err := osarch.ArchitecturePersonalities(archID)
- if err != nil {
+ // Same thing.
+ if a[i].Architecture == a[j].Architecture {
return false
}
- for _, personality := range personalities {
- personalityName, err := osarch.ArchitectureName(personality)
- if err != nil {
- return false
- }
+ // Look for native.
+ if isNative(a[i].Architecture) {
+ return true
+ }
- if personalityName == a[i].Architecture {
- return true
- }
+ // Look for personality.
+ if isPersonality(a[i].Architecture) && !isNative(a[j].Architecture) {
+ return true
}
return false
More information about the lxc-devel
mailing list