MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / copy_file

Function copy_file

tests/test_runtime_settings.c:539–552  ·  view source on GitHub ↗

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

Source from the content-addressed store, hash-verified

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. */
539static 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
554static bool journal_is_hot(const char *path) {
555 static const unsigned char magic[8] = {0xd9, 0xd5, 0x05, 0xf9, 0x20, 0xa1, 0x63, 0xd7};

Callers 1

leave_hot_journalFunction · 0.85

Calls 3

cbm_fopenFunction · 0.85
freadFunction · 0.85
fwriteFunction · 0.85

Tested by

no test coverage detected