A process killed mid-write (crash, taskkill /F, power loss) leaves _config.db * with a hot rollback journal. Made portably and deterministically: snapshot the * database and its journal while a spilled write transaction is open, roll the * transaction back, then put the snapshot back. The journal is checked to be * hot (SQLite's magic and a nonzero record count) before the code under test * r
| 537 | * hot (SQLite's magic and a nonzero record count) before the code under test |
| 538 | * runs, so these tests cannot pass on a journal that was never hot. */ |
| 539 | static bool copy_file(const char *from, const char *to) { |
| 540 | FILE *in = cbm_fopen(from, "rb"); |
| 541 | FILE *out = in ? cbm_fopen(to, "wb") : NULL; |
| 542 | bool ok = in && out; |
| 543 | char buffer[8192]; |
| 544 | size_t got = 0; |
| 545 | while (ok && (got = fread(buffer, 1, sizeof(buffer), in)) > 0) |
| 546 | ok = fwrite(buffer, 1, got, out) == got; |
| 547 | if (in) |
| 548 | fclose(in); |
| 549 | if (out && fclose(out) != 0) |
| 550 | ok = false; |
| 551 | return ok; |
| 552 | } |
| 553 | |
| 554 | static bool journal_is_hot(const char *path) { |
| 555 | static const unsigned char magic[8] = {0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7}; |
no test coverage detected