Fix bd-dvd and bd-ymj: Parent resurrection and export metadata
Bug 1 (bd-dvd): GetNextChildID now attempts parent resurrection from JSONL before failing. Added TryResurrectParent call to match CreateIssue behavior. Bug 2 (bd-ymj): Export now updates last_import_hash metadata to prevent 'JSONL content has changed' errors on subsequent exports. Files changed: - internal/storage/sqlite/hash_ids.go: Add resurrection attempt - cmd/bd/daemon_sync.go: Add metadata updates after export - Tests added for both fixes - Fixed pre-existing bug in integrity_content_test.go Follow-up work tracked in epic bd-ar2 (9 issues for improvements). Fixes GH #334
This commit is contained in:
@@ -306,6 +306,27 @@ func createExportFunc(ctx context.Context, store storage.Storage, autoCommit, au
|
||||
}
|
||||
log.log("Exported to JSONL")
|
||||
|
||||
// Update last_import_hash metadata to prevent "content has changed" errors (bd-ymj fix)
|
||||
// This keeps metadata in sync after export so next export doesn't fail
|
||||
if currentHash, err := computeJSONLHash(jsonlPath); err == nil {
|
||||
if err := store.SetMetadata(exportCtx, "last_import_hash", currentHash); err != nil {
|
||||
log.log("Warning: failed to update last_import_hash: %v", err)
|
||||
}
|
||||
exportTime := time.Now().Format(time.RFC3339)
|
||||
if err := store.SetMetadata(exportCtx, "last_import_time", exportTime); err != nil {
|
||||
log.log("Warning: failed to update last_import_time: %v", err)
|
||||
}
|
||||
// Store mtime for fast-path optimization
|
||||
if jsonlInfo, statErr := os.Stat(jsonlPath); statErr == nil {
|
||||
mtimeStr := fmt.Sprintf("%d", jsonlInfo.ModTime().Unix())
|
||||
if err := store.SetMetadata(exportCtx, "last_import_mtime", mtimeStr); err != nil {
|
||||
log.log("Warning: failed to update last_import_mtime: %v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.log("Warning: failed to compute JSONL hash for metadata update: %v", err)
|
||||
}
|
||||
|
||||
// Update database mtime to be >= JSONL mtime (fixes #278, #301, #321)
|
||||
// This prevents validatePreExport from incorrectly blocking on next export
|
||||
// with "JSONL is newer than database" after daemon auto-export
|
||||
@@ -496,6 +517,27 @@ func createSyncFunc(ctx context.Context, store storage.Storage, autoCommit, auto
|
||||
}
|
||||
log.log("Exported to JSONL")
|
||||
|
||||
// Update last_import_hash metadata to prevent "content has changed" errors (bd-ymj fix)
|
||||
// This keeps metadata in sync after export so next export doesn't fail
|
||||
if currentHash, err := computeJSONLHash(jsonlPath); err == nil {
|
||||
if err := store.SetMetadata(syncCtx, "last_import_hash", currentHash); err != nil {
|
||||
log.log("Warning: failed to update last_import_hash: %v", err)
|
||||
}
|
||||
exportTime := time.Now().Format(time.RFC3339)
|
||||
if err := store.SetMetadata(syncCtx, "last_import_time", exportTime); err != nil {
|
||||
log.log("Warning: failed to update last_import_time: %v", err)
|
||||
}
|
||||
// Store mtime for fast-path optimization
|
||||
if jsonlInfo, statErr := os.Stat(jsonlPath); statErr == nil {
|
||||
mtimeStr := fmt.Sprintf("%d", jsonlInfo.ModTime().Unix())
|
||||
if err := store.SetMetadata(syncCtx, "last_import_mtime", mtimeStr); err != nil {
|
||||
log.log("Warning: failed to update last_import_mtime: %v", err)
|
||||
}
|
||||
}
|
||||
} else {
|
||||
log.log("Warning: failed to compute JSONL hash for metadata update: %v", err)
|
||||
}
|
||||
|
||||
// Update database mtime to be >= JSONL mtime (fixes #278, #301, #321)
|
||||
// This prevents validatePreExport from incorrectly blocking on next export
|
||||
dbPath := filepath.Join(beadsDir, "beads.db")
|
||||
|
||||
Reference in New Issue
Block a user