15 const std::filesystem::path
root_dir =
".index";
21 if (std::filesystem::is_directory(
root_dir))
24 std::filesystem::remove_all(
root_dir);
27 if (!std::filesystem::create_directory(
root_dir))
29 throw std::logic_error(
30 fmt::format(
"Could not create directory: {}",
root_dir));
38 ccf::indexing::LFSMsg::store,
39 [&](
const uint8_t* data,
size_t size) {
40 auto [key, encrypted] =
41 ringbuffer::read_message<ccf::indexing::LFSMsg::store>(data, size);
43 const auto target_path =
root_dir / key;
44 std::ofstream f(target_path, std::ios::trunc | std::ios::binary);
46 "Writing {} byte file to {}", encrypted.size(), target_path);
48 reinterpret_cast<char const*
>(encrypted.data()), encrypted.size());
54 ccf::indexing::LFSMsg::get,
55 [&](
const uint8_t* data,
size_t size) {
57 ringbuffer::read_message<ccf::indexing::LFSMsg::get>(data, size);
59 const auto target_path =
root_dir / key;
60 if (std::filesystem::is_regular_file(target_path))
62 std::ifstream f(target_path, std::ios::binary);
64 const auto file_size = f.tellg();
66 "Reading {} byte file from {}",
67 static_cast<size_t>(file_size),
72 f.read(
reinterpret_cast<char*
>(blob.data()), blob.size());
75 ccf::indexing::LFSMsg::response,
writer, key, blob);
81 ccf::indexing::LFSMsg::not_found,
writer, key);
#define LOG_INFO_FMT
Definition internal_logger.h:15
#define LOG_TRACE_FMT
Definition internal_logger.h:13
#define DISPATCHER_SET_MESSAGE_HANDLER(DISP, MSG,...)
Definition messaging.h:316
std::vector< uint8_t > LFSEncryptedContents
Definition lfs_interface.h:18
std::shared_ptr< AbstractWriter > WriterPtr
Definition ring_buffer_types.h:154
#define RINGBUFFER_WRITE_MESSAGE(MSG,...)
Definition ring_buffer_types.h:259
Definition lfs_file_handler.h:14
LFSFileHandler(ringbuffer::WriterPtr &&w)
Definition lfs_file_handler.h:19
const std::filesystem::path root_dir
Definition lfs_file_handler.h:15
void register_message_handlers(messaging::RingbufferDispatcher &disp)
Definition lfs_file_handler.h:34
ringbuffer::WriterPtr writer
Definition lfs_file_handler.h:17