summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAndrew Jeffery <andrew@aj.id.au>2018-02-21 16:29:48 +1030
committerAndrew Jeffery <andrew@aj.id.au>2018-03-24 13:59:32 +1030
commitfaaa71cab957a05b8d005c219be96d2261e21750 (patch)
treebfd594422a989c21e68273d9a1130490601b4111
parenta76199bb11136b082589fc5ac1b5fdca2182b4d2 (diff)
downloadphosphor-mboxd-faaa71cab957a05b8d005c219be96d2261e21750.tar.gz
phosphor-mboxd-faaa71cab957a05b8d005c219be96d2261e21750.zip
pnor_partition_table: Hoist partition existence check from parseTocLine()
Enforce some separation of concerns: Parsing the text of a ToC entry is an operation independent of testing whether context derived from the parsed data is valid. Specifically, testing whether a file at a path derived from the ToC entry is valid inside the parser is unhelpful when we try to reuse the parser for test code, where we want to set up an environment as described by the ToC entry. Under this condition the file is of course not going to exist - we're parsing the ToC entry in order to create it. So, lets hoist the test out to the caller, enabling re-use of the parser in the test code. Change-Id: Ibc9b62c00b95b8296b48ccf45630cb5344347bd7 Signed-off-by: Andrew Jeffery <andrew@aj.id.au>
-rw-r--r--pnor_partition_table.cpp27
-rw-r--r--pnor_partition_table.hpp5
2 files changed, 17 insertions, 15 deletions
diff --git a/pnor_partition_table.cpp b/pnor_partition_table.cpp
index 9c9fb9c..8ee43c0 100644
--- a/pnor_partition_table.cpp
+++ b/pnor_partition_table.cpp
@@ -151,8 +151,7 @@ static inline void writeNameAndId(pnor_partition& part, std::string&& name,
part.data.id = std::stoul(id);
}
-bool Table::parseTocLine(fs::path& dir, const std::string& line,
- pnor_partition& part)
+bool Table::parseTocLine(const std::string& line, pnor_partition& part)
{
static constexpr auto ID_MATCH = 1;
static constexpr auto NAME_MATCH = 2;
@@ -175,14 +174,6 @@ bool Table::parseTocLine(fs::path& dir, const std::string& line,
return false;
}
- fs::path partitionFile = dir;
- partitionFile /= match[NAME_MATCH].str();
- if (!fs::exists(partitionFile))
- {
- MSG_ERR("Partition file %s does not exist", partitionFile.c_str());
- return false;
- }
-
writeNameAndId(part, match[NAME_MATCH].str(), match[ID_MATCH].str());
writeDefaults(part);
@@ -211,10 +202,24 @@ void Table::preparePartitions()
while (std::getline(file, line))
{
- if (parseTocLine(directory, line, table.partitions[numParts]))
+ pnor_partition& part = table.partitions[numParts];
+ fs::path file;
+
+ if (!parseTocLine(line, part))
+ {
+ continue;
+ }
+
+ file = directory;
+ file /= part.data.name;
+ if (fs::exists(file))
{
++numParts;
}
+ else
+ {
+ MSG_ERR("Partition file %s does not exist", file.c_str());
+ }
}
}
diff --git a/pnor_partition_table.hpp b/pnor_partition_table.hpp
index 9d254d8..a333b5f 100644
--- a/pnor_partition_table.hpp
+++ b/pnor_partition_table.hpp
@@ -147,16 +147,13 @@ class Table
/** @brief Parse a ToC line (entry) into the corresponding FFS partition
* object.
*
- * @param[in] dir - The parent directory of the FFS partition files
- * described in the ToC.
* @param[in] line - The ToC line to parse
* @param[out] part - The partition object to populate with the information
* parsed from the provided ToC line
*
* @returns True on success, false on failure.
*/
- bool parseTocLine(fs::path& dir, const std::string& line,
- pnor_partition& part);
+ bool parseTocLine(const std::string& line, pnor_partition& part);
/** @brief Prepares a vector of PNOR partition structures.
*/
OpenPOWER on IntegriCloud