Skip to content

Commit

Permalink
api: Improve code style for a few operations
Browse files Browse the repository at this point in the history
Simplify one boolean expression, and adjust style of code when returning
a CheckInResult instance.

Signed-off-by: Andre Detsch <[email protected]>
  • Loading branch information
detsch committed Aug 27, 2024
1 parent 6622841 commit 30aca22
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions src/api.cc
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ static std::vector<TufTarget> filterTargets(const std::vector<TufTarget>& allTar
CheckInResult AkliteClient::checkInFailure(CheckInResult::Status check_status, std::string err_msg) const {
LOG_ERROR << err_msg;
client_->notifyTufUpdateFinished(err_msg);
return CheckInResult{check_status, hw_id_, {}};
return {check_status, hw_id_, {}};
}

std::shared_ptr<aklite::tuf::RepoSource> AkliteClient::getRepoSource(
Expand Down Expand Up @@ -335,7 +335,7 @@ CheckInResult AkliteClient::CheckIn() const {
if (invoke_post_cb_at_checkin_) {
client_->notifyTufUpdateFinished();
}
return CheckInResult(CheckInResult::Status::Ok, hw_id_, matchingTargets);
return {CheckInResult::Status::Ok, hw_id_, matchingTargets};
}

static bool compareTargets(const Uptane::Target& t1, const Uptane::Target& t2) {
Expand Down Expand Up @@ -543,7 +543,7 @@ CheckInResult AkliteClient::CheckInLocal(const LocalUpdateSource* local_update_s
}

std::tie(check_status, err_msg) = updateMeta(local_update_source);
if (!(check_status == CheckInResult::Status::Ok || check_status == CheckInResult::Status::OkCached)) {
if (check_status != CheckInResult::Status::Ok && check_status != CheckInResult::Status::OkCached) {
return checkInFailure(check_status, err_msg);
}

Expand Down Expand Up @@ -583,7 +583,7 @@ CheckInResult AkliteClient::CheckInLocal(const LocalUpdateSource* local_update_s
if (invoke_post_cb_at_checkin_) {
client_->notifyTufUpdateFinished();
}
return CheckInResult(check_status, hw_id_, toTufTargets(available_targets));
return {check_status, hw_id_, toTufTargets(available_targets)};
}

CheckInResult AkliteClient::CheckInCurrent(const LocalUpdateSource* local_update_source) const {
Expand All @@ -595,7 +595,7 @@ CheckInResult AkliteClient::CheckInCurrent(const LocalUpdateSource* local_update
} catch (const std::exception& exc) {
err_msg = std::string("Stored TUF metadata is invalid: ") + exc.what();
LOG_WARNING << err_msg;
return CheckInResult{CheckInResult::Status::SecurityError, hw_id_, {}};
return {CheckInResult::Status::SecurityError, hw_id_, {}};
}

LOG_INFO << "Searching for matching TUF Targets...";
Expand All @@ -606,7 +606,7 @@ CheckInResult AkliteClient::CheckInCurrent(const LocalUpdateSource* local_update
err_msg = boost::str(boost::format("No Target found for the device; hw ID: %s; tags: %s") % hw_id_ %
boost::algorithm::join(client_->tags, ","));
LOG_ERROR << err_msg;
return CheckInResult{CheckInResult::Status::NoMatchingTargets, hw_id_, {}};
return {CheckInResult::Status::NoMatchingTargets, hw_id_, {}};
}
LOG_INFO << "Latest targets metadata contains " << matchingTargets.size() << " entries for tag=\""
<< boost::algorithm::join(client_->tags, ",") << "\" and hardware id=\"" << hw_id_ << "\"";
Expand All @@ -625,12 +625,12 @@ CheckInResult AkliteClient::CheckInCurrent(const LocalUpdateSource* local_update
err_msg = "No update content found in ostree dir " + src.OstreeRepoDir.string() + " and app dir " +
src.AppsDir.string();
LOG_ERROR << err_msg;
return CheckInResult(CheckInResult::Status::NoTargetContent, hw_id_, std::vector<TufTarget>{});
return {CheckInResult::Status::NoTargetContent, hw_id_, std::vector<TufTarget>{}};
}
return CheckInResult(CheckInResult::Status::OkCached, hw_id_, toTufTargets(available_targets));
return {CheckInResult::Status::OkCached, hw_id_, toTufTargets(available_targets)};

} else {
return CheckInResult(CheckInResult::Status::OkCached, hw_id_, matchingTargets);
return {CheckInResult::Status::OkCached, hw_id_, matchingTargets};
}
}

Expand Down

0 comments on commit 30aca22

Please sign in to comment.