Make JSON reading safer

- Check that the file actually opened before reading it
- If the JSON was discarded, then make just use an empty object
This commit is contained in:
Pk11
2021-03-23 04:47:49 -05:00
parent 5343661069
commit 77edd99749
7 changed files with 65 additions and 39 deletions
-6
View File
@@ -50,19 +50,15 @@ public:
std::vector<std::string> GetInstalled(const std::string &unistoreName, const std::string &entry) const;
void SetUpdated(const std::string &unistoreName, const std::string &entry, const std::string &updated) {
if (this->metadataJson.is_discarded()) return;
this->metadataJson[unistoreName][entry]["updated"] = updated;
};
void SetMarks(const std::string &unistoreName, const std::string &entry, int marks) {
if (this->metadataJson.is_discarded()) return;
this->metadataJson[unistoreName][entry]["marks"] = marks;
};
/* TODO: Handle this better. */
void SetInstalled(const std::string &unistoreName, const std::string &entry, const std::string &name) {
if (this->metadataJson.is_discarded()) return;
const std::vector<std::string> installs = this->GetInstalled(unistoreName, entry);
bool write = true;
@@ -82,8 +78,6 @@ public:
/* Remove installed state from a download list entry. */
void RemoveInstalled(const std::string &unistoreName, const std::string &entry, const std::string &name) {
if (this->metadataJson.is_discarded()) return;
const std::vector<std::string> installs = this->GetInstalled(unistoreName, entry);
int idx = -1;