The following pull request was submitted through Github.
It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/6773

This e-mail was sent by the LXC bot, direct replies will not reach the author
unless they happen to be subscribed to this list.

=== Description (from pull-request) ===
Signed-off-by: Stéphane Graber <stgra...@ubuntu.com>
From 433f0ca1c15174a28cd18492802ae7073142d124 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgra...@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 <stgra...@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
_______________________________________________
lxc-devel mailing list
lxc-devel@lists.linuxcontainers.org
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to