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

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) ===
This fixes #5809 

Signed-off-by: Thomas Hipp <[email protected]>
From dd4a2dda6b841e2c8fc54527692c19413139cf4c Mon Sep 17 00:00:00 2001
From: Thomas Hipp <[email protected]>
Date: Mon, 3 Jun 2019 16:42:26 +0200
Subject: [PATCH] lxd/db: Sort container snapshots by creation date

Signed-off-by: Thomas Hipp <[email protected]>
---
 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
_______________________________________________
lxc-devel mailing list
[email protected]
http://lists.linuxcontainers.org/listinfo/lxc-devel

Reply via email to