Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fio extras] storage: allow target to be marked as bad #77

Draft
wants to merge 3 commits into
base: 2024.03+fio
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/libaktualizr/storage/invstorage.h
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct MisconfiguredEcu {
EcuState state;
};

enum class InstalledVersionUpdateMode { kNone, kCurrent, kPending };
enum class InstalledVersionUpdateMode { kNone, kCurrent, kPending, kBadTarget };

// Functions loading/storing multiple pieces of data are supposed to do so
// atomically as far as implementation makes it possible.
Expand Down
11 changes: 11 additions & 0 deletions src/libaktualizr/storage/sqlstorage.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1118,6 +1118,17 @@ void SQLStorage::saveInstalledVersion(const std::string& ecu_serial, const Uptan
LOG_ERROR << "Failed to save installed versions: " << db.errmsg();
return;
}
} else if (update_mode == InstalledVersionUpdateMode::kBadTarget) {
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

At first glance, it looks like this if is better suited in the if else below before if (!!old_id).

if (update_mode == InstalledVersionUpdateMode::kBadTarget) {
...
} else if (!!old_id) {
...

What do you think?

// unset 'pending' and 'was_installed' for all installations of the target in the current ecu
auto statement = db.prepareStatement<std::string, std::string>(
"UPDATE installed_versions SET is_pending = 0, was_installed = 0 WHERE ecu_serial = ? AND name = ?",
ecu_serial_real, target.filename());
if (statement.step() != SQLITE_DONE) {
LOG_ERROR << "Failed to save installed versions: " << db.errmsg();
return;
}
db.commitTransaction();
return;
}

if (!!old_id) {
Expand Down