Skip to content

Commit

Permalink
Merge pull request #109 from cajun-rat/various-tidy
Browse files Browse the repository at this point in the history
Various tidy-ups
  • Loading branch information
cajun-rat authored Apr 29, 2024
2 parents cdc604b + cc33025 commit dad1cbe
Show file tree
Hide file tree
Showing 6 changed files with 25 additions and 24 deletions.
8 changes: 4 additions & 4 deletions src/libaktualizr/package_manager/packagemanagerfake.cc
Original file line number Diff line number Diff line change
Expand Up @@ -35,21 +35,21 @@ data::InstallationResult PackageManagerFake::install(const Uptane::Target& targe
if (fiu_fail("fake_package_install") != 0) {
std::string failure_cause = fault_injection_last_info();
if (failure_cause.empty()) {
return data::InstallationResult(data::ResultCode::Numeric::kInstallFailed, "");
return {data::ResultCode::Numeric::kInstallFailed, ""};
}
LOG_DEBUG << "Causing installation failure with message: " << failure_cause;
return data::InstallationResult(data::ResultCode(data::ResultCode::Numeric::kInstallFailed, failure_cause), "");
return {data::ResultCode(data::ResultCode::Numeric::kInstallFailed, failure_cause), ""};
}

if (config.fake_need_reboot) {
// set reboot flag to be notified later
if (bootloader_ != nullptr) {
bootloader_->rebootFlagSet();
}
return data::InstallationResult(data::ResultCode::Numeric::kNeedCompletion, "Application successful, need reboot");
return {data::ResultCode::Numeric::kNeedCompletion, "Application successful, need reboot"};
}

return data::InstallationResult(data::ResultCode::Numeric::kOk, "Installing package was successful");
return {data::ResultCode::Numeric::kOk, "Installing package was successful"};
}

void PackageManagerFake::completeInstall() const {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ static int ProgressHandler(void* clientp, curl_off_t dltotal, curl_off_t dlnow,
ds->time_lastreport = now;
}
}
if (ds->token != nullptr && !ds->token->canContinue(false)) {
if (ds->token != nullptr && ds->token->hasAborted()) {
return 1;
}
return 0;
Expand Down
23 changes: 11 additions & 12 deletions src/libaktualizr/primary/aktualizr.cc
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,19 @@
#include "utilities/timer.h"

using std::make_shared;
using std::move;
using std::shared_ptr;

Aktualizr::Aktualizr(const Config &config)
: Aktualizr(config, INvStorage::newStorage(config.storage), std::make_shared<HttpClient>()) {}

Aktualizr::Aktualizr(Config config, std::shared_ptr<INvStorage> storage_in,
const std::shared_ptr<HttpInterface> &http_in)
: config_{move(config)}, sig_{new event::Channel()}, api_queue_{new api::CommandQueue()} {
: config_{std::move(config)}, sig_{new event::Channel()}, api_queue_{new api::CommandQueue()} {
if (sodium_init() == -1) { // Note that sodium_init doesn't require a matching 'sodium_deinit'
throw std::runtime_error("Unable to initialize libsodium");
}

storage_ = move(storage_in);
storage_ = std::move(storage_in);
storage_->importData(config_.import);

uptane_client_ = std::make_shared<SotaUptaneClient>(config_, storage_, http_in, sig_, api_queue_->FlowControlToken());
Expand Down Expand Up @@ -127,7 +126,7 @@ std::vector<SecondaryInfo> Aktualizr::GetSecondaries() const {

std::future<result::CampaignCheck> Aktualizr::CampaignCheck() {
std::function<result::CampaignCheck()> task([this] { return uptane_client_->campaignCheck(); });
return api_queue_->enqueue(move(task));
return api_queue_->enqueue(std::move(task));
}

std::future<void> Aktualizr::CampaignControl(const std::string &campaign_id, campaign::Cmd cmd) {
Expand All @@ -146,28 +145,28 @@ std::future<void> Aktualizr::CampaignControl(const std::string &campaign_id, cam
break;
}
});
return api_queue_->enqueue(move(task));
return api_queue_->enqueue(std::move(task));
}

void Aktualizr::SetCustomHardwareInfo(Json::Value hwinfo) { uptane_client_->setCustomHardwareInfo(move(hwinfo)); }
void Aktualizr::SetCustomHardwareInfo(Json::Value hwinfo) { uptane_client_->setCustomHardwareInfo(std::move(hwinfo)); }
std::future<void> Aktualizr::SendDeviceData() {
std::function<void()> task([this] { uptane_client_->sendDeviceData(); });
return api_queue_->enqueue(move(task));
return api_queue_->enqueue(std::move(task));
}

std::future<result::UpdateCheck> Aktualizr::CheckUpdates() {
std::function<result::UpdateCheck()> task([this] { return uptane_client_->fetchMeta(); });
return api_queue_->enqueue(move(task));
return api_queue_->enqueue(std::move(task));
}

std::future<result::Download> Aktualizr::Download(const std::vector<Uptane::Target> &updates) {
std::function<result::Download()> task([this, updates]() { return uptane_client_->downloadImages(updates); });
return api_queue_->enqueue(move(task));
return api_queue_->enqueue(std::move(task));
}

std::future<result::Install> Aktualizr::Install(const std::vector<Uptane::Target> &updates) {
std::function<result::Install()> task([this, updates] { return uptane_client_->uptaneInstall(updates); });
return api_queue_->enqueue(move(task));
return api_queue_->enqueue(std::move(task));
}

bool Aktualizr::SetInstallationRawReport(const std::string &custom_raw_report) {
Expand All @@ -176,7 +175,7 @@ bool Aktualizr::SetInstallationRawReport(const std::string &custom_raw_report) {

std::future<bool> Aktualizr::SendManifest(const Json::Value &custom) {
std::function<bool()> task([this, custom]() { return uptane_client_->putManifest(custom); });
return api_queue_->enqueue(move(task));
return api_queue_->enqueue(std::move(task));
}

result::Pause Aktualizr::Pause() {
Expand Down Expand Up @@ -220,7 +219,7 @@ Aktualizr::InstallationLog Aktualizr::GetInstallationLog() {
std::vector<Uptane::Target> log;
storage_->loadInstallationLog(serial.ToString(), &log, true);

ilog.emplace_back(Aktualizr::InstallationLogEntry{serial, move(log)});
ilog.emplace_back(Aktualizr::InstallationLogEntry{serial, std::move(log)});
}

return ilog;
Expand Down
7 changes: 3 additions & 4 deletions src/libaktualizr/primary/provisioner.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,15 @@
#include "logging/logging.h"

using std::map;
using std::move;
using std::shared_ptr;

Provisioner::Provisioner(const ProvisionConfig& config, shared_ptr<INvStorage> storage,
shared_ptr<HttpInterface> http_client, shared_ptr<KeyManager> key_manager,
const map<Uptane::EcuSerial, shared_ptr<SecondaryInterface>>& secondaries)
: config_(config),
storage_(move(storage)),
http_client_(move(http_client)),
key_manager_(move(key_manager)),
storage_(std::move(storage)),
http_client_(std::move(http_client)),
key_manager_(std::move(key_manager)),
secondaries_(secondaries) {}

void Provisioner::SecondariesWereChanged() { current_state_ = State::kUnknown; }
Expand Down
8 changes: 5 additions & 3 deletions src/libaktualizr/uptane/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,12 @@ add_library(uptane OBJECT ${SOURCES})
add_aktualizr_test(NAME tuf SOURCES tuf_test.cc PROJECT_WORKING_DIRECTORY)

if(BUILD_OSTREE AND SOTA_PACKED_CREDENTIALS)
add_aktualizr_test(NAME uptane_ci SOURCES uptane_ci_test.cc PROJECT_WORKING_DIRECTORY
ARGS ${SOTA_PACKED_CREDENTIALS} ${PROJECT_BINARY_DIR}/ostree_repo)
add_aktualizr_test(NAME uptane_ci SOURCES uptane_ci_test.cc
PROJECT_WORKING_DIRECTORY
LIBRARIES virtual_secondary
ARGS ${SOTA_PACKED_CREDENTIALS} ${PROJECT_BINARY_DIR}/ostree_repo)
set_tests_properties(test_uptane_ci PROPERTIES LABELS "credentials")
target_link_libraries(t_uptane_ci virtual_secondary)

else(BUILD_OSTREE AND SOTA_PACKED_CREDENTIALS)
list(APPEND TEST_SOURCES uptane_ci_test.cc)
endif(BUILD_OSTREE AND SOTA_PACKED_CREDENTIALS)
Expand Down
1 change: 1 addition & 0 deletions src/libaktualizr/utilities/types.cc
Original file line number Diff line number Diff line change
Expand Up @@ -112,6 +112,7 @@ const std::map<data::ResultCode::Numeric, const char *> data::ResultCode::string
{ResultCode::Numeric::kGeneralError, "GENERAL_ERROR"},
{ResultCode::Numeric::kNeedCompletion, "NEED_COMPLETION"},
{ResultCode::Numeric::kCustomError, "CUSTOM_ERROR"},
{ResultCode::Numeric::kOperationCancelled, "OPERATION_CANCELLED"},
{ResultCode::Numeric::kUnknown, "UNKNOWN"},
};

Expand Down

0 comments on commit dad1cbe

Please sign in to comment.