mirror of
https://github.com/davidallendj/magellan.git
synced 2025-12-20 11:37:01 -07:00
Fixed removing from cache with --with-* flags
This commit is contained in:
parent
6e483064e0
commit
0106bb969a
1 changed files with 13 additions and 3 deletions
16
internal/cache/sqlite/sqlite.go
vendored
16
internal/cache/sqlite/sqlite.go
vendored
|
|
@ -2,6 +2,7 @@ package sqlite
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/davidallendj/magellan/internal/util"
|
"github.com/davidallendj/magellan/internal/util"
|
||||||
magellan "github.com/davidallendj/magellan/pkg"
|
magellan "github.com/davidallendj/magellan/pkg"
|
||||||
|
|
@ -113,13 +114,22 @@ func DeleteRemoteAssets(path string, assets ...magellan.RemoteAsset) error {
|
||||||
}
|
}
|
||||||
tx = db.MustBegin()
|
tx = db.MustBegin()
|
||||||
for _, asset := range assets {
|
for _, asset := range assets {
|
||||||
|
// skip if neither host nor port are specified
|
||||||
if asset.Host == "" && asset.Port <= 0 {
|
if asset.Host == "" && asset.Port <= 0 {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
sql := fmt.Sprintf(`DELETE FROM %s WHERE port=:port;`, TABLE_NAME)
|
sql := fmt.Sprintf(`DELETE FROM %s`, TABLE_NAME)
|
||||||
if asset.Host != "" {
|
where := []string{}
|
||||||
sql += "AND host=:host"
|
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)
|
_, err := tx.NamedExec(sql, &asset)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Printf("failed to execute DELETE transaction: %v\n", err)
|
fmt.Printf("failed to execute DELETE transaction: %v\n", err)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue