From f9170de5ba9b6def031407c73e21f91826801861 Mon Sep 17 00:00:00 2001 From: Mike Sul Date: Mon, 2 Dec 2024 17:39:22 +0100 Subject: [PATCH] apps: Make sure app fetch check is done once Make sure that the check whether app is fetched is performed only once during a single update cycle. - If app is not running then don't check if it is fetched since it going to be re-updated anyway which implies checking for missing app blobs and pulling them if any. - If app is enabled for running and is running but not fetched then there is no need to check whether it is fetched during checking "reset" apps. Signed-off-by: Mike Sul --- src/composeappmanager.cc | 24 +++++++++++++++++++----- src/composeappmanager.h | 8 ++++++-- 2 files changed, 25 insertions(+), 7 deletions(-) diff --git a/src/composeappmanager.cc b/src/composeappmanager.cc index 61d3447a..23df2363 100644 --- a/src/composeappmanager.cc +++ b/src/composeappmanager.cc @@ -194,7 +194,8 @@ ComposeAppManager::AppsContainer ComposeAppManager::getApps(const Uptane::Target } ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane::Target& t, - AppsSyncReason& apps_and_reasons) const { + AppsSyncReason& apps_and_reasons, + std::set& fetched_apps) const { AppsContainer apps_to_update; auto currently_installed_target_apps = Target::appsJson(OstreeManager::getCurrent()); @@ -244,6 +245,7 @@ ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane LOG_INFO << app_name << " is not fully fetched; missing blobs will be fetched"; continue; } + fetched_apps.insert(app_name); } return apps_to_update; @@ -251,9 +253,10 @@ ComposeAppManager::AppsContainer ComposeAppManager::getAppsToUpdate(const Uptane ComposeAppManager::AppsSyncReason ComposeAppManager::checkForAppsToUpdate(const Uptane::Target& target) { AppsSyncReason apps_and_reasons; - cur_apps_to_fetch_and_update_ = getAppsToUpdate(target, apps_and_reasons); + std::set fetched_apps; + cur_apps_to_fetch_and_update_ = getAppsToUpdate(target, apps_and_reasons, fetched_apps); if (!!cfg_.reset_apps) { - cur_apps_to_fetch_ = getAppsToFetch(target); + cur_apps_to_fetch_ = getAppsToFetch(target, true, &cur_apps_to_fetch_and_update_, &fetched_apps); } are_apps_checked_ = true; for (const auto& app : cur_apps_to_fetch_) { @@ -718,8 +721,9 @@ ComposeAppManager::AppsContainer ComposeAppManager::getRequiredApps(const Config return apps; } -ComposeAppManager::AppsContainer ComposeAppManager::getAppsToFetch(const Uptane::Target& target, - bool check_store) const { +ComposeAppManager::AppsContainer ComposeAppManager::getAppsToFetch(const Uptane::Target& target, bool check_store, + const AppsContainer* checked_apps, + const std::set* fetched_apps) const { auto enabled_apps{getRequiredApps(cfg_, target)}; if (!check_store) { return enabled_apps; @@ -727,6 +731,16 @@ ComposeAppManager::AppsContainer ComposeAppManager::getAppsToFetch(const Uptane: AppsContainer apps_to_be_fetched; for (const auto& app : enabled_apps) { + if (checked_apps != nullptr && checked_apps->count(app.first) > 0) { + // no reason to check whether app is fetched since app is checked and marked for update because + // it is either not installed or not running; + continue; + } + if (fetched_apps != nullptr && fetched_apps->count(app.first) > 0) { + // no reason to check whether app is fetched since this check was already done before because this + // app is enabled for running. + continue; + } if (!app_engine_->isFetched({app.first, app.second})) { apps_to_be_fetched.insert(app); } diff --git a/src/composeappmanager.h b/src/composeappmanager.h index fc59469c..80ed963c 100644 --- a/src/composeappmanager.h +++ b/src/composeappmanager.h @@ -3,6 +3,7 @@ #include #include +#include #include #include "docker/composeappengine.h" @@ -59,7 +60,8 @@ class ComposeAppManager : public RootfsTreeManager { // Returns an intersection of Target's Apps and Apps listed in the config (sota.toml:compose_apps) // 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, AppsSyncReason& apps_and_reasons) const; + AppsContainer getAppsToUpdate(const Uptane::Target& t, AppsSyncReason& apps_and_reasons, + std::set& fetched_apps) const; AppsSyncReason checkForAppsToUpdate(const Uptane::Target& target); void setAppsNotChecked() { are_apps_checked_ = false; } void handleRemovedApps(const Uptane::Target& target) const; @@ -72,7 +74,9 @@ class ComposeAppManager : public RootfsTreeManager { Json::Value getRunningAppsInfo() const; std::string getRunningAppsInfoForReport() const; - AppsContainer getAppsToFetch(const Uptane::Target& target, bool check_store = true) const; + AppsContainer getAppsToFetch(const Uptane::Target& target, bool check_store = true, + const AppsContainer* checked_apps = nullptr, + const std::set* fetched_apps = nullptr) const; void stopDisabledComposeApps(const Uptane::Target& target) const; void removeDisabledComposeApps(const Uptane::Target& target) const; void forEachRemovedApp(const Uptane::Target& target,