y2err(tmp);
for (const string& tmp : cmd.get_stderr())
y2err(tmp);
+
+ SN_THROW(Exception(_("Failed to load info.xml.")));
}
content = boost::join(cmd.get_stdout(), "");
string CmdMetaParse::get_checksum() const
{
if (!content.length())
- return "";
+ {
+ y2err(sformat("The content of %s is empty.", path.c_str()));
+ SN_THROW(Exception(_("The content of info.xml is empty.")));
+ }
unsigned char hash[SHA256_DIGEST_LENGTH];
SHA256(reinterpret_cast<const unsigned char*>(content.c_str()), content.length(),
SnapshotMeta CmdMetaParse::get_meta() const
{
- SnapshotMeta meta;
-
if (!content.length())
{
- // The `info.xml` file might be missing.
- // Using fallback values for snapshot metadata.
- return meta;
+ y2err(sformat("The content of %s is empty.", path.c_str()));
+ SN_THROW(Exception(_("The content of info.xml is empty.")));
}
+ SnapshotMeta meta;
+
XmlFile file(XmlFile::FromString, content);
const xmlNode* node = file.getRootElement();
string tmp;
if (!getChildValue(node, "type", tmp) || !toValue(tmp, meta.type, true))
{
- // Log error for the missing attribute and retain the default value.
y2err("The type attribute is missing from " << path);
+ SN_THROW(Exception(_("The type attribute is missing from `info.xml`.")));
}
getChildValue(node, "pre_num", meta.pre_num);
getChildValue(node, "cleanup", meta.cleanup);
- for (const xmlNode* tmp : getChildNodes(node, "userdata"))
+ for (const xmlNode* tmp_node : getChildNodes(node, "userdata"))
{
string key, value;
- getChildValue(tmp, "key", key);
- getChildValue(tmp, "value", value);
+ getChildValue(tmp_node, "key", key);
+ getChildValue(tmp_node, "value", value);
if (!key.empty())
meta.userdata[key] = value;
}
+ meta.state = SnapshotMeta::State::VALID;
+
return meta;
}
using std::string;
- struct SnapshotMeta
+ class SnapshotMeta
{
+ public:
+
+ enum class State
+ {
+ /**
+ * Errors occurred while processing the content of `info.xml`. Either the file
+ * does not exist or some attributes are missing. The state of `SnapshotMeta`
+ * is invalid.
+ */
+ INVALID,
+
+ /**
+ * The content of `info.xml` has been successfully processed. The state of
+ * `SnapshotMeta` is valid.
+ */
+ VALID
+ };
+
+ State state = State::INVALID;
SnapshotType type = SnapshotType::SINGLE;
unsigned int pre_num = 0;
string cleanup;