[lxc-devel] [lxd/master] lxd/db: Sort container snapshots by creation date
monstermunchkin on Github
lxc-bot at linuxcontainers.org
Mon Jun 3 14:47:31 UTC 2019
A non-text attachment was scrubbed...
Name: not available
Type: text/x-mailbox
Size: 376 bytes
Desc: not available
URL: <http://lists.linuxcontainers.org/pipermail/lxc-devel/attachments/20190603/041d6ab7/attachment.bin>
-------------- next part --------------
From dd4a2dda6b841e2c8fc54527692c19413139cf4c Mon Sep 17 00:00:00 2001
From: Thomas Hipp <thomas.hipp at canonical.com>
Date: Mon, 3 Jun 2019 16:42:26 +0200
Subject: [PATCH] lxd/db: Sort container snapshots by creation date
Signed-off-by: Thomas Hipp <thomas.hipp at canonical.com>
---
lxd/db/containers.go | 11 ++++++++++-
1 file changed, 10 insertions(+), 1 deletion(-)
diff --git a/lxd/db/containers.go b/lxd/db/containers.go
index 5081c0c178..e8709ebb3a 100644
--- a/lxd/db/containers.go
+++ b/lxd/db/containers.go
@@ -3,6 +3,7 @@ package db
import (
"database/sql"
"fmt"
+ "sort"
"strings"
"time"
@@ -915,6 +916,7 @@ SELECT containers.name
FROM containers
JOIN projects ON projects.id = containers.project_id
WHERE projects.name=? AND containers.type=? AND SUBSTR(containers.name,1,?)=?
+ORDER BY date(containers.creation_date)
`
inargs := []interface{}{project, CTypeSnapshot, length, regexp}
outfmt := []interface{}{name}
@@ -938,7 +940,14 @@ func (c *ClusterTx) ContainerGetSnapshotsFull(project string, name string) ([]Co
Type: int(CTypeSnapshot),
}
- return c.ContainerList(filter)
+ snapshots, err := c.ContainerList(filter)
+ if err != nil {
+ return nil, err
+ }
+
+ sort.Slice(snapshots, func(i, j int) bool { return snapshots[i].CreationDate.Before(snapshots[j].CreationDate) })
+
+ return snapshots, nil
}
// ContainerNextSnapshot returns the index the next snapshot of the container
More information about the lxc-devel
mailing list