[lxc-devel] [lxd/master] Fix sorting order of devices
stgraber on Github
lxc-bot at linuxcontainers.org
Tue Aug 22 15:15:50 UTC 2017
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 419 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20170822/e6fce020/attachment.bin>
-------------- next part --------------
From 6f1114560a4818c5c6b2a170c1b89f332b997edf Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?St=C3=A9phane=20Graber?= <stgraber at ubuntu.com>
Date: Tue, 22 Aug 2017 02:35:40 -0400
Subject: [PATCH] Fix sorting order of devices
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Make sure we always get the exact same order.
Closes #2895
Signed-off-by: Stéphane Graber <stgraber at ubuntu.com>
---
lxd/types/devices.go | 13 +++++++++----
1 file changed, 9 insertions(+), 4 deletions(-)
diff --git a/lxd/types/devices.go b/lxd/types/devices.go
index 263f4c435..8f735715c 100644
--- a/lxd/types/devices.go
+++ b/lxd/types/devices.go
@@ -132,14 +132,19 @@ func (devices sortableDevices) Less(i, j int) bool {
a := devices[i]
b := devices[j]
+ // First sort by types
+ if a.device["type"] != b.device["type"] {
+ return a.device["type"] < b.device["type"]
+ }
+
+ // Special case disk paths
if a.device["type"] == "disk" && b.device["type"] == "disk" {
- if a.device["path"] == b.device["path"] {
- return a.name < b.name
+ if a.device["path"] != b.device["path"] {
+ return a.device["path"] < b.device["path"]
}
-
- return a.device["path"] < b.device["path"]
}
+ // Fallback to sorting by names
return a.name < b.name
}
More information about the lxc-devel
mailing list