Skip to content

Commit

Permalink
api: extended: Report which apps require update in DownloadStarted event
Browse files Browse the repository at this point in the history
Signed-off-by: Andre Detsch <[email protected]>
  • Loading branch information
detsch committed Aug 28, 2024
1 parent 9b85698 commit b47394a
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 11 deletions.
7 changes: 5 additions & 2 deletions src/aklite_client_ext.cc
Original file line number Diff line number Diff line change
Expand Up @@ -120,15 +120,18 @@ GetTargetToInstallResult AkliteClientExt::GetTargetToInstall(const CheckInResult
<< " Skipping its installation.";
}

if (force_apps_sync || !client_->appsInSync(Target::fromTufTarget(current))) {
auto apps_to_update = client_->appsToUpdate(Target::fromTufTarget(current));
if (force_apps_sync || !apps_to_update.empty()) {
// Force installation of apps
res.selected_target = current;
LOG_INFO
<< "The specified Target is already installed, enforcing installation to make sure it's synced and running:"
<< res.selected_target.Name();

LOG_INFO << "XX " << apps_to_update.size()
<< " Apps requiring update: " + boost::algorithm::join(apps_to_update, ", ");
res.status = GetTargetToInstallResult::Status::UpdateSyncApps;
res.reason = "Syncing Active Target Apps";
res.reason = "Syncing Active Target Apps\nApps requiring update: " + boost::algorithm::join(apps_to_update, ", ");
} else {
// No targets to install
res.selected_target = TufTarget();
Expand Down
15 changes: 13 additions & 2 deletions src/composeappmanager.cc
Original file line number Diff line number Diff line change
Expand Up @@ -237,13 +237,24 @@ ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane
return apps_to_update;
}

bool ComposeAppManager::checkForAppsToUpdate(const Uptane::Target& target) {
std::vector<std::string> ComposeAppManager::checkForAppsToUpdate(const Uptane::Target& target) {
cur_apps_to_fetch_and_update_ = getAppsToUpdate(target);
if (!!cfg_.reset_apps) {
cur_apps_to_fetch_ = getAppsToFetch(target);
}
are_apps_checked_ = true;
return cur_apps_to_fetch_and_update_.empty() && cur_apps_to_fetch_.empty();
std::vector<std::string> ret;
for (const auto& app : cur_apps_to_fetch_and_update_) {
if (std::find(ret.begin(), ret.end(), app.first) == ret.end()) {
ret.push_back(app.first);
}
}
for (const auto& app : cur_apps_to_fetch_) {
if (std::find(ret.begin(), ret.end(), app.first) == ret.end()) {
ret.push_back(app.first);
}
}
return ret;
}

DownloadResult ComposeAppManager::Download(const TufTarget& target) {
Expand Down
2 changes: 1 addition & 1 deletion src/composeappmanager.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class ComposeAppManager : public RootfsTreeManager {
// If Apps are not specified in the config then all Target's Apps are returned
AppsContainer getApps(const Uptane::Target& t) const;
AppsContainer getAppsToUpdate(const Uptane::Target& t) const;
bool checkForAppsToUpdate(const Uptane::Target& target);
std::vector<std::string> checkForAppsToUpdate(const Uptane::Target& target);
void setAppsNotChecked() { are_apps_checked_ = false; }
void handleRemovedApps(const Uptane::Target& target) const;
Json::Value getAppsState() const;
Expand Down
14 changes: 8 additions & 6 deletions src/liteclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -771,22 +771,24 @@ bool LiteClient::isTargetActive(const Uptane::Target& target) const {
return target.filename() == current.filename() && target.sha256Hash() == current.sha256Hash();
}

bool LiteClient::appsInSync(const Uptane::Target& target) const {
bool LiteClient::appsInSync(const Uptane::Target& target) const { return appsToUpdate(target).empty(); }

std::vector<std::string> LiteClient::appsToUpdate(const Uptane::Target& target) const {
if (package_manager_->name() == ComposeAppManager::Name) {
auto* compose_pacman = dynamic_cast<ComposeAppManager*>(package_manager_.get());
if (compose_pacman == nullptr) {
LOG_ERROR << "Cannot downcast the package manager to a specific type";
return false;
return {};
}
LOG_INFO << "Checking status of Active Target (" << target.filename() << ")";
auto no_any_app_to_update = compose_pacman->checkForAppsToUpdate(target);
if (no_any_app_to_update) {
auto apps_to_update = compose_pacman->checkForAppsToUpdate(target);
if (apps_to_update.empty()) {
compose_pacman->handleRemovedApps(getCurrent());
}

return no_any_app_to_update;
return apps_to_update;
}
return true;
return {};
}

void LiteClient::setAppsNotChecked() {
Expand Down
1 change: 1 addition & 0 deletions src/liteclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,7 @@ class LiteClient {
void reportAppsState();
bool isTargetActive(const Uptane::Target& target) const;
bool appsInSync(const Uptane::Target& target) const;
std::vector<std::string> appsToUpdate(const Uptane::Target& target) const;
void setAppsNotChecked();
std::string getDeviceID() const;
static void update_request_headers(std::shared_ptr<HttpClient>& http_client, const Uptane::Target& target,
Expand Down

0 comments on commit b47394a

Please sign in to comment.