1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41
|
static int kvstore_create_snapshot(kvstore* store) { if (!store) return KVSTORE_ERR_NULL;
const char* tmp = "data.snapshot.tmp"; const char* snap = "data.snapshot";
FILE* fp = fopen(tmp, "w"); if (!fp) { perror("fopen snapshot"); return KVSTORE_ERR_INTERNAL; }
if (bptree_scan(store->tree, snapshot_write_cb, fp) != 0) { fclose(fp); return KVSTORE_ERR_INTERNAL; }
fflush(fp); fsync(fileno(fp)); fclose(fp);
if (rename(tmp, snap) != 0) { perror("rename snapshot"); return KVSTORE_ERR_NULL; } return KVSTORE_OK; }
|