improvement: Don't deserialize again if past attempt failed

Store the state of deserialization such that we only
attemp once when no persisted blobs were found.

Signed-off-by: Kun Yi <kunyi731@gmail.com>
Change-Id: I1d7f605eeff724849429d2ee8fb28b0aa4c05381
diff --git a/binarystore.cpp b/binarystore.cpp
index 1c94dd3..e036e0a 100644
--- a/binarystore.cpp
+++ b/binarystore.cpp
@@ -54,7 +54,8 @@
 {
     /* Load blob from sysfile if we know it might not match what we have.
      * Note it will overwrite existing unsaved data per design. */
-    if (commitState_ == CommitState::Clean)
+    if (commitState_ == CommitState::Clean ||
+        commitState_ == CommitState::Uninitialized)
     {
         return true;
     }
@@ -71,11 +72,7 @@
         {
             /* Fail to parse the data, which might mean no preexsiting blobs
              * and is a valid case to handle. Simply init an empty binstore. */
-            log<level::WARNING>(
-                "Fail to parse. There might be no persisted blobs",
-                entry("BASE_ID=%s", baseBlobId_.c_str()));
-
-            return true;
+            commitState_ = CommitState::Uninitialized;
         }
     }
     catch (const std::system_error& e)
@@ -87,7 +84,14 @@
     }
     catch (const std::exception& e)
     {
-        log<level::WARNING>("Invalid size. There might be no persisted blobs.");
+        /* Non system error originates from junk value in 'size' */
+        commitState_ = CommitState::Uninitialized;
+    }
+
+    if (commitState_ == CommitState::Uninitialized)
+    {
+        log<level::WARNING>("Fail to parse. There might be no persisted blobs",
+                            entry("BASE_ID=%s", baseBlobId_.c_str()));
         return true;
     }
 
diff --git a/binarystore.hpp b/binarystore.hpp
index f07cf7b..3a25581 100644
--- a/binarystore.hpp
+++ b/binarystore.hpp
@@ -142,9 +142,10 @@
   private:
     enum class CommitState
     {
-        Dirty,      // In-memory data might not match persisted data
-        Clean,      // In-memory data matches persisted data
-        CommitError // Error happened during committing
+        Dirty,         // In-memory data might not match persisted data
+        Clean,         // In-memory data matches persisted data
+        Uninitialized, // Cannot find persisted data
+        CommitError    // Error happened during committing
     };
 
     /* Load the serialized data from sysfile if commit state is dirty.