16 const std::filesystem::path
root_dir =
".index";
22 if (std::filesystem::is_directory(
root_dir))
26 "Clearing LFS index directory - remove_all({})",
root_dir));
27 std::filesystem::remove_all(
root_dir);
32 "Creating LFS index directory - create_directory({})",
root_dir));
33 if (!std::filesystem::create_directory(
root_dir))
35 throw std::logic_error(
36 fmt::format(
"Could not create directory: {}",
root_dir));
45 ccf::indexing::LFSMsg::store,
46 [&](
const uint8_t* data,
size_t size) {
47 auto [key, encrypted] =
48 ringbuffer::read_message<ccf::indexing::LFSMsg::store>(data, size);
50 const auto target_path =
root_dir / key;
53 "Writing LFS file ({} bytes) - ofstream({})",
56 std::ofstream f(target_path, std::ios::trunc | std::ios::binary);
58 "Writing {} byte file to {}", encrypted.size(), target_path);
60 reinterpret_cast<char const*
>(encrypted.data()),
68 ccf::indexing::LFSMsg::get,
69 [&](
const uint8_t* data,
size_t size) {
71 ringbuffer::read_message<ccf::indexing::LFSMsg::get>(data, size);
73 const auto target_path =
root_dir / key;
74 if (std::filesystem::is_regular_file(target_path))
77 fmt::format(
"Reading LFS file - ifstream({})", target_path));
78 std::ifstream f(target_path, std::ios::binary);
80 const auto file_size = f.tellg();
82 "Reading {} byte file from {}",
83 static_cast<size_t>(file_size),
88 f.read(
reinterpret_cast<char*
>(blob.data()), blob.size());
91 ccf::indexing::LFSMsg::response,
writer, key, blob);
97 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:292
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:15
LFSFileHandler(ringbuffer::WriterPtr &&w)
Definition lfs_file_handler.h:20
const std::filesystem::path root_dir
Definition lfs_file_handler.h:16
void register_message_handlers(messaging::RingbufferDispatcher &disp)
Definition lfs_file_handler.h:41
ringbuffer::WriterPtr writer
Definition lfs_file_handler.h:18
Definition time_bound_logger.h:14