cleanup: Operate on members directly and allow empty paths in the lookup table

Instead of using private methods to change data, directly operate on
it. Currently no test depends on these methods.

There is also a minor bug fix: the previous code will not increment or
decrement the open session count if the blobId is an empty string,
however there is no check on the manager side. If empty blobIds are
disallowed they should be checked earlier.

Signed-off-by: Kun Yi <kunyi731@gmail.com>
Change-Id: I8d97e098bed2d5c27a204a86ed688d0d9a98f0a2
diff --git a/manager.cpp b/manager.cpp
index 286b81a..15ff083 100644
--- a/manager.cpp
+++ b/manager.cpp
@@ -25,55 +25,18 @@
 namespace blobs
 {
 
-void BlobManager::incrementOpen(const std::string& path)
-{
-    if (path.empty())
-    {
-        return;
-    }
-
-    openFiles[path] += 1;
-}
-
-void BlobManager::decrementOpen(const std::string& path)
-{
-    if (path.empty())
-    {
-        return;
-    }
-
-    /* TODO(venture): Check into the iterator from find, does it makes sense
-     * to just update it directly? */
-    auto entry = openFiles.find(path);
-    if (entry != openFiles.end())
-    {
-        /* found it, decrement it and remove it if 0. */
-        openFiles[path] -= 1;
-        if (openFiles[path] == 0)
-        {
-            openFiles.erase(path);
-        }
-    }
-}
-
-int BlobManager::getOpen(const std::string& path) const
-{
-    /* No need to input check on the read-only call. */
-    auto entry = openFiles.find(path);
-    if (entry != openFiles.end())
-    {
-        return entry->second;
-    }
-
-    return 0;
-}
-
 void BlobManager::eraseSession(GenericBlobInterface* handler, uint16_t session)
 {
     sessions.erase(session);
     /* Ok for openSessions[handler] to be an empty set */
     openSessions[handler].erase(session);
-    decrementOpen(getPath(session));
+
+    auto path = getPath(session);
+    openFiles[path]--;
+    if (openFiles[path] == 0)
+    {
+        openFiles.erase(path);
+    }
 }
 
 void BlobManager::cleanUpStaleSessions(GenericBlobInterface* handler)
@@ -189,7 +152,7 @@
     /* Associate session with handler */
     sessions[*session] = SessionInfo(path, handler, flags);
     openSessions[handler].insert(*session);
-    incrementOpen(path);
+    openFiles[path]++;
     return true;
 }
 
@@ -310,7 +273,7 @@
     }
 
     /* Check if the file has any open handles. */
-    if (getOpen(path) > 0)
+    if (openFiles[path] > 0)
     {
         return false;
     }
diff --git a/manager.hpp b/manager.hpp
index 011fe88..cba7935 100644
--- a/manager.hpp
+++ b/manager.hpp
@@ -276,10 +276,6 @@
     std::string getPath(uint16_t session) const;
 
   private:
-    void incrementOpen(const std::string& path);
-    void decrementOpen(const std::string& path);
-    int getOpen(const std::string& path) const;
-
     /* Helper method to erase a session from all maps */
     void eraseSession(GenericBlobInterface* handler, uint16_t session);
     /* For each session owned by this handler, call expire if it is stale */