fix: Bug where renaming the main folder did not update db path

settings where the ones of the previous folder.
This commit is contained in:
2026-06-18 11:20:20 +02:00
parent 59f1775fcd
commit b6d991b799
6 changed files with 93 additions and 33 deletions
+25 -2
View File
@@ -523,8 +523,22 @@ func (a *App) startup(ctx context.Context) {
// Windows reinstall. It lives OUTSIDE the DB since we must know the path
// before opening it.
if custom := readDBPointer(dataDir); custom != "" {
a.dbPath = custom
usingDefault = false
// Portability guard: a pointer that is merely ANOTHER folder's default DB
// location ("…/<other>/data/opslog.db") means the portable folder was
// renamed or copied — its config.json still points at the original. Ignore
// it and use THIS folder's own data (and clear the stale pointer so it
// stops happening). A genuine custom location — another drive, a different
// filename — is NOT default-style, so it's still honoured.
stale := strings.EqualFold(filepath.Base(custom), "opslog.db") &&
strings.EqualFold(filepath.Base(filepath.Dir(custom)), "data") &&
!strings.EqualFold(filepath.Clean(filepath.Dir(custom)), filepath.Clean(dataDir))
if stale {
fmt.Printf("OpsLog: ignoring stale DB pointer %q (folder moved) — using %s\n", custom, a.dbPath)
_ = writeDBPointer(dataDir, "")
} else {
a.dbPath = custom
usingDefault = false
}
}
if err := os.MkdirAll(filepath.Dir(a.dbPath), 0o755); err != nil {
a.startupErr = "cannot create db folder: " + err.Error()
@@ -3174,6 +3188,15 @@ func (a *App) DeleteQSO(id int64) error {
return a.qso.Delete(a.ctx, id)
}
// DeleteQSOs removes several QSOs at once (multi-row selection). Returns the
// number actually deleted.
func (a *App) DeleteQSOs(ids []int64) (int64, error) {
if a.qso == nil {
return 0, fmt.Errorf("db not initialized")
}
return a.qso.DeleteMany(a.ctx, ids)
}
// QSLBulkUpdate carries the paper-QSL fields to apply to a selection. An empty
// string leaves that field unchanged (so you can set only "received = Y + date"
// without touching the sent side).