lxd/db/images.go
func (c *Cluster) ImageExists(project string, fingerprint string) (bool, error) {
	err := c.Transaction(func(tx *ClusterTx) error {
		enabled, err := tx.ProjectHasImages(project)
		if err != nil {
			return errors.Wrap(err, "Check if project has images")
		}
		if !enabled {
			project = "default"
		}
		return nil
	})
	if err != nil {
		return false, err
	}

	var exists bool
	query := `
SELECT COUNT(*) > 0
  FROM images
  JOIN projects ON projects.id = images.project_id
 WHERE projects.name = ? AND fingerprint=?
`
	inargs := []interface{}{project, fingerprint}
	outargs := []interface{}{&exists}
	err = dbQueryRowScan(c.db, query, inargs, outargs)
	if err == sql.ErrNoRows {
		return exists, ErrNoSuchObject
	}

	return exists, err
}
func (c *Cluster) ImageExists(project string, fingerprint string) (bool, error) {
	err := c.Transaction(func(tx *ClusterTx) error {
		enabled, err := tx.ProjectHasImages(project)
		if err != nil {
			return errors.Wrap(err, "Check if project has images")
		}
		if !enabled {
			project = "default"
		}
		return nil
	})
	if err != nil {
		return false, err
	}

	var exists bool
	query := `
SELECT COUNT(*) > 0
  FROM images
  JOIN projects ON projects.id = images.project_id
 WHERE projects.name = ? AND fingerprint=?
`
	inargs := []interface{}{project, fingerprint}
	outargs := []interface{}{&exists}
	err = dbQueryRowScan(c.db, query, inargs, outargs)
	if err == sql.ErrNoRows {
		return exists, ErrNoSuchObject
	}

	return exists, err
}
// ImageExists returns whether an image with the given fingerprint exists.