Fix daemon crash when backup/vc.db files exist
- Changed backup file filtering from checking file extension (.backup) to checking if filename contains '.backup' - This now properly filters files like 'beads.backup-pre-hash-20251030-171258.db' - Also exclude vc.db from database detection - Add strings import to beads.go - Improve error message to suggest manual removal Fixes bd-373c
This commit is contained in:
7
beads.go
7
beads.go
@@ -12,6 +12,7 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"os"
|
"os"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"strings"
|
||||||
|
|
||||||
"github.com/steveyegge/beads/internal/configfile"
|
"github.com/steveyegge/beads/internal/configfile"
|
||||||
"github.com/steveyegge/beads/internal/storage"
|
"github.com/steveyegge/beads/internal/storage"
|
||||||
@@ -198,12 +199,12 @@ func findDatabaseInTree() string {
|
|||||||
// Found .beads/ directory, look for *.db files
|
// Found .beads/ directory, look for *.db files
|
||||||
matches, err := filepath.Glob(filepath.Join(beadsDir, "*.db"))
|
matches, err := filepath.Glob(filepath.Join(beadsDir, "*.db"))
|
||||||
if err == nil && len(matches) > 0 {
|
if err == nil && len(matches) > 0 {
|
||||||
// Filter out backup files
|
// Filter out backup files and vc.db
|
||||||
var validDBs []string
|
var validDBs []string
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
baseName := filepath.Base(match)
|
baseName := filepath.Base(match)
|
||||||
// Skip backup files (e.g., beads.db.backup, bd.db.backup)
|
// Skip backup files (contains ".backup" in name) and vc.db
|
||||||
if filepath.Ext(baseName) != ".backup" {
|
if !strings.Contains(baseName, ".backup") && baseName != "vc.db" {
|
||||||
validDBs = append(validDBs, match)
|
validDBs = append(validDBs, match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1361,10 +1361,12 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush bool, logPath, p
|
|||||||
beadsDir := filepath.Dir(daemonDBPath)
|
beadsDir := filepath.Dir(daemonDBPath)
|
||||||
matches, err := filepath.Glob(filepath.Join(beadsDir, "*.db"))
|
matches, err := filepath.Glob(filepath.Join(beadsDir, "*.db"))
|
||||||
if err == nil && len(matches) > 1 {
|
if err == nil && len(matches) > 1 {
|
||||||
// Filter out backup files
|
// Filter out backup files (*.backup-*.db, *.backup.db)
|
||||||
var validDBs []string
|
var validDBs []string
|
||||||
for _, match := range matches {
|
for _, match := range matches {
|
||||||
if filepath.Ext(filepath.Base(match)) != ".backup" {
|
baseName := filepath.Base(match)
|
||||||
|
// Skip if it's a backup file (contains ".backup" in name)
|
||||||
|
if !strings.Contains(baseName, ".backup") && baseName != "vc.db" {
|
||||||
validDBs = append(validDBs, match)
|
validDBs = append(validDBs, match)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -1375,7 +1377,7 @@ func runDaemonLoop(interval time.Duration, autoCommit, autoPush bool, logPath, p
|
|||||||
}
|
}
|
||||||
log.log("")
|
log.log("")
|
||||||
log.log("Beads requires a single canonical database: %s", beads.CanonicalDatabaseName)
|
log.log("Beads requires a single canonical database: %s", beads.CanonicalDatabaseName)
|
||||||
log.log("Run 'bd init' to migrate legacy databases")
|
log.log("Run 'bd init' to migrate legacy databases or manually remove old databases")
|
||||||
os.Exit(1)
|
os.Exit(1)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user