From 248f68f6a2060319fa18dda2df8c47205db1219a Mon Sep 17 00:00:00 2001 From: Green Sky Date: Sat, 6 Apr 2024 11:57:48 +0200 Subject: [PATCH] minimal stack creation refactor (wip) --- src/fragment_store/fragment_store.cpp | 30 ++++++++++++++++++++------- 1 file changed, 22 insertions(+), 8 deletions(-) diff --git a/src/fragment_store/fragment_store.cpp b/src/fragment_store/fragment_store.cpp index bdb92cd3..5caa8cc7 100644 --- a/src/fragment_store/fragment_store.cpp +++ b/src/fragment_store/fragment_store.cpp @@ -51,14 +51,11 @@ static ByteSpan spanFromRead(const std::variant>& } // TODO: these stacks are file specific -static std::stack> buildFileStackRead(std::string_view file_path, Encryption encryption, Compression compression) { - std::stack> file_stack; - file_stack.push(std::make_unique(file_path)); - if (!file_stack.top()->isGood()) { - std::cerr << "FS error: opening file for reading '" << file_path << "'\n"; - return {}; - } +// add enc and comp file layers +// assumes a file is already in the stack +static bool buildStackRead(std::stack>& file_stack, Encryption encryption, Compression compression) { + assert(!file_stack.empty()); // TODO: decrypt here assert(encryption == Encryption::NONE); @@ -72,7 +69,24 @@ static std::stack> buildFileStackRead(std::string_view f } if (!file_stack.top()->isGood()) { - std::cerr << "FS error: file failed to add " << (int)compression << " decompression layer '" << file_path << "'\n"; + std::cerr << "FS error: file failed to add " << (int)compression << " decompression layer\n"; + return false; + } + + return true; +} + +static std::stack> buildFileStackRead(std::string_view file_path, Encryption encryption, Compression compression) { + std::stack> file_stack; + file_stack.push(std::make_unique(file_path)); + + if (!file_stack.top()->isGood()) { + std::cerr << "FS error: opening file for reading '" << file_path << "'\n"; + return {}; + } + + if (!buildStackRead(file_stack, encryption, compression)) { + std::cerr << "FS error: file failed to add layers for '" << file_path << "'\n"; return {}; }