The following pull request was submitted through Github. It can be accessed and reviewed at: https://github.com/lxc/lxd/pull/3817
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 <[email protected]>
From 92e52ddbb426c36e340b182a49b696ab27758021 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Graber?= <[email protected]> Date: Tue, 19 Sep 2017 15:18:45 -0400 Subject: [PATCH] images: Properly extract the image expiry MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Stéphane Graber <[email protected]> --- lxd/db/images.go | 29 +++++++++++++++++++++++++---- 1 file changed, 25 insertions(+), 4 deletions(-) diff --git a/lxd/db/images.go b/lxd/db/images.go index 66e1d6be1..b2d259925 100644 --- a/lxd/db/images.go +++ b/lxd/db/images.go @@ -40,11 +40,14 @@ func ImagesGet(db *sql.DB, public bool) ([]string, error) { } func ImagesGetExpired(db *sql.DB, expiry int64) ([]string, error) { - q := `SELECT fingerprint FROM images WHERE cached=1 AND creation_date<=strftime('%s', date('now', '-` + fmt.Sprintf("%d", expiry) + ` day'))` + q := `SELECT fingerprint, last_use_date, upload_date FROM images WHERE cached=1` + + var fpStr string + var useStr string + var uploadStr string - var fp string inargs := []interface{}{} - outfmt := []interface{}{fp} + outfmt := []interface{}{fpStr, useStr, uploadStr} dbResults, err := QueryScan(db, q, inargs, outfmt) if err != nil { return []string{}, err @@ -52,10 +55,28 @@ func ImagesGetExpired(db *sql.DB, expiry int64) ([]string, error) { results := []string{} for _, r := range dbResults { + // Figure out the expiry + timestamp := r[2] + if r[1] != "" { + timestamp = r[1] + } + + var imageExpiry time.Time + err = imageExpiry.UnmarshalText([]byte(timestamp.(string))) + if err != nil { + return []string{}, err + } + imageExpiry = imageExpiry.Add(time.Duration(expiry*24) * time.Hour) + + // Check if expired + if imageExpiry.After(time.Now()) { + continue + } + results = append(results, r[0].(string)) } - return results, nil + return []string{}, nil } func ImageSourceInsert(db *sql.DB, imageId int, server string, protocol string, certificate string, alias string) error {
_______________________________________________ lxc-devel mailing list [email protected] http://lists.linuxcontainers.org/listinfo/lxc-devel
