The body of reopenIfReplaced, without the in-flight-sync guard.
()
| 379 | |
| 380 | /** The body of {@link reopenIfReplaced}, without the in-flight-sync guard. */ |
| 381 | private reopenReplacedDatabase(): boolean { |
| 382 | if (!this.db.isReplacedOnDisk()) return false; |
| 383 | const dbPath = this.db.getPath(); |
| 384 | // Open the live file FIRST — if that throws (e.g. mid-recreate), the old |
| 385 | // handle stays in place and the caller retries on the next query, rather |
| 386 | // than leaving this instance with no connection at all. |
| 387 | const fresh = DatabaseConnection.open(dbPath, { readOnly: this.db.readOnly }); |
| 388 | const stale = this.db; |
| 389 | this.db = fresh; |
| 390 | this.queries = new QueryBuilder(fresh.getDb()); |
| 391 | this.wireLayers(); |
| 392 | // Whoever reopened — a sync, or a tool call's self-heal — the next sync |
| 393 | // must reconcile the whole tree (#1902). |
| 394 | this.pendingFullReconcile = true; |
| 395 | // Releasing the dead handle also frees the leaked db/-wal/-shm fds that were |
| 396 | // pinning the unlinked inode (#925). |
| 397 | try { stale.close(); } catch { /* the old inode is gone; closing just frees fds */ } |
| 398 | return true; |
| 399 | } |
| 400 | |
| 401 | // =========================================================================== |
| 402 | // Lifecycle Methods |
no test coverage detected