Fix: Update DB mtime after import even with 0 changes (#296)
When bd import finds no changes (0 created, 0 updated), it now updates the database modification timestamp to signal sync validation passed. This fixes 'bd sync' refusing to export with 'JSONL is newer than database' error that occurs after git pull updates JSONL mtime without content changes. Root cause: Import validated DB/JSONL are in sync but didn't update DB mtime, causing timestamp-based sync validation to perpetually fail. Amp-Thread-ID: https://ampcode.com/threads/T-560b9c11-e368-45e6-b1e3-512b6d6010a1 Co-authored-by: Amp <amp@ampcode.com>
This commit is contained in:
@@ -309,12 +309,13 @@ NOTE: Import requires direct database access and does not work with daemon mode.
|
||||
}
|
||||
|
||||
// Update database mtime to reflect it's now in sync with JSONL
|
||||
// This prevents bd doctor from incorrectly warning that JSONL is newer
|
||||
// Only touch if actual changes were made (not dry-run, not unchanged-only)
|
||||
if result.Created > 0 || result.Updated > 0 || len(result.IDMapping) > 0 {
|
||||
if err := touchDatabaseFile(dbPath, input); err != nil {
|
||||
debug.Logf("Warning: failed to update database mtime: %v", err)
|
||||
}
|
||||
// This is CRITICAL even when import found 0 changes, because:
|
||||
// 1. Import validates DB and JSONL are in sync (no content divergence)
|
||||
// 2. Without mtime update, bd sync refuses to export (thinks JSONL is newer)
|
||||
// 3. This can happen after git pull updates JSONL mtime but content is identical
|
||||
// Fix for: refusing to export: JSONL is newer than database (import first to avoid data loss)
|
||||
if err := touchDatabaseFile(dbPath, input); err != nil {
|
||||
debug.Logf("Warning: failed to update database mtime: %v", err)
|
||||
}
|
||||
|
||||
// Print summary
|
||||
|
||||
Reference in New Issue
Block a user