Joedb 9.1.4
The Journal-Only Embedded Database
Loading...
Searching...
No Matches
inplace_pack.cpp
Go to the documentation of this file.
2#include "joedb/ui/dump.h"
5
6#include <cstdio>
7
8namespace joedb
9{
10 void inplace_pack(const std::string &file_name)
11 {
12 const std::string packed = file_name + ".packed";
13
14 {
15 File input_file(file_name, Open_Mode::read_existing);
16 File output_file(packed, Open_Mode::create_new);
17 Readonly_Journal input_journal(input_file);
18 Writable_Journal output_journal(output_file);
19 pack(input_journal, output_journal);
20 }
21
22 const std::string unpacked = file_name + ".unpacked";
23
24 if
25 (
26 std::rename(file_name.c_str(), unpacked.c_str()) ||
27 std::rename(packed.c_str(), file_name.c_str())
28 )
29 {
30 throw Exception("error moving files");
31 }
32 }
33}
@ create_new
fails if already exists, locks the file for writing
@ read_existing
fails if does not exist
void pack(Readonly_Journal &input_journal, Writable &writable)
Definition dump.cpp:220
void inplace_pack(const std::string &file_name)
Definition Blob.h:7
JOEDB_FILE File
Definition File.h:25