diff --git a/src/liteclient.cc b/src/liteclient.cc index 82573e97..21a8acf6 100644 --- a/src/liteclient.cc +++ b/src/liteclient.cc @@ -757,7 +757,7 @@ 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, bool cleanup_removed_apps) const { if (package_manager_->name() == ComposeAppManager::Name) { auto* compose_pacman = dynamic_cast(package_manager_.get()); if (compose_pacman == nullptr) { @@ -766,7 +766,7 @@ bool LiteClient::appsInSync(const Uptane::Target& target) const { } LOG_INFO << "Checking Active Target status..."; auto no_any_app_to_update = compose_pacman->checkForAppsToUpdate(target); - if (no_any_app_to_update) { + if (cleanup_removed_apps && no_any_app_to_update) { compose_pacman->handleRemovedApps(getCurrent()); } diff --git a/src/liteclient.h b/src/liteclient.h index 77362fb7..7ed7abf5 100644 --- a/src/liteclient.h +++ b/src/liteclient.h @@ -67,7 +67,7 @@ class LiteClient { void reportHwInfo(); void reportAppsState(); bool isTargetActive(const Uptane::Target& target) const; - bool appsInSync(const Uptane::Target& target) const; + bool appsInSync(const Uptane::Target& target, bool cleanup_removed_apps = true) const; void setAppsNotChecked(); std::string getDeviceID() const; static void update_request_headers(std::shared_ptr& http_client, const Uptane::Target& target, diff --git a/src/main.cc b/src/main.cc index ac282e19..e49887b2 100644 --- a/src/main.cc +++ b/src/main.cc @@ -259,6 +259,7 @@ static int daemon_main(LiteClient& client, const bpo::variables_map& variables_m std::string cor_id; storage::Volume::UsageInfo stat; } state_when_download_failed{Hash{"", ""}, "", {.err = "undefined"}}; + bool cleanup_removed_apps = true; while (true) { LOG_INFO << "Active Target: " << current.filename() << ", sha256: " << current.sha256Hash(); @@ -399,7 +400,7 @@ static int daemon_main(LiteClient& client, const bpo::variables_map& variables_m << " Skipping its installation."; } data::ResultCode::Numeric rc{data::ResultCode::Numeric::kOk}; - if (!client.appsInSync(current)) { + if (!client.appsInSync(current, cleanup_removed_apps)) { client.checkForUpdatesEnd(target_to_install); rc = do_app_sync(client); if (rc == data::ResultCode::Numeric::kOk) { @@ -411,6 +412,8 @@ static int daemon_main(LiteClient& client, const bpo::variables_map& variables_m LOG_INFO << "Device is up-to-date"; client.checkForUpdatesEnd(Uptane::Target::Unknown()); } + // Automatically cleanup during check only once. A cleanup will also occur after a new target is installed + cleanup_removed_apps = false; } } catch (const std::exception& exc) {