From 46955795b034ed4b058958bba620bd8965ce91f7 Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 13 Apr 2024 21:04:40 +0200 Subject: [PATCH] fix dir not properly seperating and other error handling --- .../object_store/backends/filesystem_storage.cpp | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/src/solanaceae/object_store/backends/filesystem_storage.cpp b/src/solanaceae/object_store/backends/filesystem_storage.cpp index bbc00fb..0218154 100644 --- a/src/solanaceae/object_store/backends/filesystem_storage.cpp +++ b/src/solanaceae/object_store/backends/filesystem_storage.cpp @@ -75,8 +75,9 @@ ObjectHandle FilesystemStorage::newObject(ByteSpan id) { object_file_path = std::filesystem::path{_storage_path}/id_hex; } else { // use the first 2hex (1byte) as a subfolder - std::filesystem::create_directories(std::string{_storage_path} + id_hex.substr(0, 2)); - object_file_path = std::filesystem::path{std::string{_storage_path} + id_hex.substr(0, 2)} / id_hex.substr(2); + const auto object_dir = std::filesystem::path{std::string{_storage_path}} / id_hex.substr(0, 2); + std::filesystem::create_directories(object_dir); + object_file_path = object_dir / id_hex.substr(2); } if (std::filesystem::exists(object_file_path)) { @@ -275,10 +276,18 @@ bool FilesystemStorage::write(Object o, std::function buffer.size()) { // wtf + assert(false); break; } - data_file_stack.top()->write({buffer.data(), buffer_actual_size}); + if (!data_file_stack.top()->write({buffer.data(), buffer_actual_size})) { + while (!meta_file_stack.empty()) { meta_file_stack.pop(); } // destroy stack // TODO: maybe work with scope? + std::filesystem::remove(meta_tmp_path); + while (!data_file_stack.empty()) { data_file_stack.pop(); } // destroy stack // TODO: maybe work with scope? + std::filesystem::remove(data_tmp_path); + std::cerr << "FS error: failed to write data\n"; + return false; + } } while (buffer_actual_size == buffer.size()); // flush // TODO: use scope