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
|
// Update database mtime to reflect it's now in sync with JSONL
|
||||||
// This prevents bd doctor from incorrectly warning that JSONL is newer
|
// This is CRITICAL even when import found 0 changes, because:
|
||||||
// Only touch if actual changes were made (not dry-run, not unchanged-only)
|
// 1. Import validates DB and JSONL are in sync (no content divergence)
|
||||||
if result.Created > 0 || result.Updated > 0 || len(result.IDMapping) > 0 {
|
// 2. Without mtime update, bd sync refuses to export (thinks JSONL is newer)
|
||||||
if err := touchDatabaseFile(dbPath, input); err != nil {
|
// 3. This can happen after git pull updates JSONL mtime but content is identical
|
||||||
debug.Logf("Warning: failed to update database mtime: %v", err)
|
// 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
|
// Print summary
|
||||||
|
|||||||
Reference in New Issue
Block a user