lxd/db/images.go
func (c *Cluster) ImagesGetExpired(expiry int64) ([]string, error) {
	q := `SELECT fingerprint, last_use_date, upload_date FROM images WHERE cached=1`

	var fpStr string
	var useStr string
	var uploadStr string

	inargs := []interface{}{}
	outfmt := []interface{}{fpStr, useStr, uploadStr}
	dbResults, err := queryScan(c.db, q, inargs, outfmt)
	if err != nil {
		return []string{}, err
	}

	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
}
func (c *Cluster) ImagesGetExpired(expiry int64) ([]string, error) {
	q := `SELECT fingerprint, last_use_date, upload_date FROM images WHERE cached=1`

	var fpStr string
	var useStr string
	var uploadStr string

	inargs := []interface{}{}
	outfmt := []interface{}{fpStr, useStr, uploadStr}
	dbResults, err := queryScan(c.db, q, inargs, outfmt)
	if err != nil {
		return []string{}, err
	}

	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
}
func ( c * Cluster ) ImagesGetExpired ( expiry int64 ) ( [ ] string , error ) { q := `SELECT fingerprint, last_use_date, upload_date FROM images WHERE cached=1` var fpStr string var useStr string var uploadStr string inargs := [ ] interface { } { } outfmt := [ ] interface { } { fpStr , useStr , uploadStr } dbResults , err := queryScan ( c . db , q , inargs , outfmt ) if err != nil { return [ ] string { } , err } 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 }
// ImagesGetExpired returns the names of all images that have expired since the
// given time.
ImagesGetExpired returns the names of all images that have expired since the given time .