Fixed removing from cache with --with-* flags

This commit is contained in:
David Allen 2024-09-19 11:21:08 -06:00 committed by David Allen
parent 6e483064e0
commit 0106bb969a
Signed by: towk
GPG key ID: 0430CDBE22619155

View file

@ -2,6 +2,7 @@ package sqlite
import (
"fmt"
"strings"
"github.com/davidallendj/magellan/internal/util"
magellan "github.com/davidallendj/magellan/pkg"
@ -113,13 +114,22 @@ func DeleteRemoteAssets(path string, assets ...magellan.RemoteAsset) error {
}
tx = db.MustBegin()
for _, asset := range assets {
// skip if neither host nor port are specified
if asset.Host == "" && asset.Port <= 0 {
continue
}
sql := fmt.Sprintf(`DELETE FROM %s WHERE port=:port;`, TABLE_NAME)
if asset.Host != "" {
sql += "AND host=:host"
sql := fmt.Sprintf(`DELETE FROM %s`, TABLE_NAME)
where := []string{}
if asset.Port > 0 {
where = append(where, "port=:port")
}
if asset.Host != "" {
where = append(where, "host=:host")
}
if len(where) <= 0 {
continue
}
sql += fmt.Sprintf(" WHERE %s;", strings.Join(where, " AND "))
_, err := tx.NamedExec(sql, &asset)
if err != nil {
fmt.Printf("failed to execute DELETE transaction: %v\n", err)