handler: Implement open as a pass-through function
When opening a blob id, handler finds a blobstore with matching
base id and calls its open function, passing down the path and open
flags.
Signed-off-by: Kun Yi <kunyi@google.com>
Change-Id: I6127b3c2b2c4752b5e094db61f12451089ccb20b
diff --git a/handler.cpp b/handler.cpp
index 4e6e6ea..7bbac6b 100644
--- a/handler.cpp
+++ b/handler.cpp
@@ -5,6 +5,17 @@
namespace blobs
{
+namespace internal
+{
+
+/* Strip the basename till the last '/' */
+std::string getBaseFromId(const std::string& blobId)
+{
+ return blobId.substr(0, blobId.find_last_of('/') + 1);
+}
+
+} // namespace internal
+
void BinaryStoreBlobHandler::addNewBinaryStore(
std::unique_ptr<binstore::BinaryStoreInterface> store)
{
@@ -61,8 +72,20 @@
return false;
}
- // TODO: implement
- return false;
+ const auto& base = internal::getBaseFromId(path);
+
+ if (stores_.find(base) == stores_.end())
+ {
+ return false;
+ }
+
+ if (!stores_[base]->openOrCreateBlob(path, flags))
+ {
+ return false;
+ }
+
+ sessions_[session] = stores_[base].get();
+ return true;
}
std::vector<uint8_t> BinaryStoreBlobHandler::read(uint16_t session,