bmc: Replace fileOpen flag
Instead of keeping track of a fileOpen flag, keep track of fileOpen
using !lookup.empty() instead.
Signed-off-by: Brandon Kim <brandonkim@google.com>
Change-Id: I09d16479d2a52deae5e8d63582376a27a6a39bb5
diff --git a/bmc/firmware_handler.cpp b/bmc/firmware_handler.cpp
index fede302..96b4eba 100644
--- a/bmc/firmware_handler.cpp
+++ b/bmc/firmware_handler.cpp
@@ -110,12 +110,12 @@
* we cannot close an active session. To enforce this, we only allow
* deleting if there isn't a file open.
*/
- if (fileOpen)
+ if (fileOpen())
{
return false;
}
- /* only includes states where fileOpen == false */
+ /* only includes states where fileOpen() == false */
switch (state)
{
case UpdateState::notYetStarted:
@@ -315,7 +315,7 @@
* verification process has begun -- which is done via commit() on the hash
* blob_id, we no longer want to allow updating the contents.
*/
- if (fileOpen)
+ if (fileOpen())
{
return false;
}
@@ -356,7 +356,7 @@
break;
case UpdateState::verificationPending:
/* Handle opening the verifyBlobId --> we know the image and hash
- * aren't open because of the fileOpen check. They can still open
+ * aren't open because of the fileOpen() check. They can still open
* other files from this state to transition back into
* uploadInProgress.
*
@@ -369,7 +369,6 @@
lookup[session] = &verifyImage;
- fileOpen = true;
return true;
}
break;
@@ -386,7 +385,6 @@
lookup[session] = &updateImage;
- fileOpen = true;
return true;
}
else
@@ -516,7 +514,6 @@
removeBlobId(verifyBlobId);
changeState(UpdateState::uploadInProgress);
- fileOpen = true;
return true;
}
@@ -753,7 +750,6 @@
}
lookup.erase(item);
- fileOpen = false;
return true;
}
diff --git a/bmc/firmware_handler.hpp b/bmc/firmware_handler.hpp
index 472bb8e..3a4b4be 100644
--- a/bmc/firmware_handler.hpp
+++ b/bmc/firmware_handler.hpp
@@ -210,6 +210,11 @@
blobIDs.end());
}
+ inline bool fileOpen()
+ {
+ return !lookup.empty();
+ }
+
ActionStatus getVerifyStatus();
ActionStatus getActionStatus();
@@ -252,9 +257,6 @@
bool preparationTriggered = false;
ActionMap actionPacks;
- /** Temporary variable to track whether a blob is open. */
- bool fileOpen = false;
-
ActionStatus lastVerificationStatus = ActionStatus::unknown;
ActionStatus lastUpdateStatus = ActionStatus::unknown;
diff --git a/ipmi_flash.md b/ipmi_flash.md
index f69d226..ef982d1 100644
--- a/ipmi_flash.md
+++ b/ipmi_flash.md
@@ -17,13 +17,13 @@
The two files are only present once their corresponding blob has been opened.
-# The state of fileOpen per state
+# The state of fileOpen() per state
You can only open one file at a time, and some of the states exist only when a
file is open.
-State | fileOpen
-:---------------------- | :-------
+State | fileOpen()
+:---------------------- | :---------
`notYetStarted` | `false`
`uploadInProgress` | `true`
`verificationPending` | `false`
@@ -49,7 +49,7 @@
**The BMC is expecting to receive bytes.**
-* `open(/flash/*)` returns false because `fileOpen == true`
+* `open(/flash/*)` returns false because `fileOpen() == true`
* `close(/flash/*)` triggers `state -> verificationPending`
@@ -95,7 +95,7 @@
**The update process has started.**
-* `open(/flash/*)`r eturns false because `fileOpen == true`
+* `open(/flash/*)`r eturns false because `fileOpen() == true`
## `updatedCompleted`