Skip to content

Commit

Permalink
Merge pull request #372 from foundriesio/detsch-dont-prune-on-every-p…
Browse files Browse the repository at this point in the history
…oll-v94

apps: Avoid pruning unused apps on every check operation
  • Loading branch information
detsch authored Dec 6, 2024
2 parents 6d34eec + 10241bd commit dc22210
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 4 deletions.
4 changes: 2 additions & 2 deletions src/liteclient.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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<ComposeAppManager*>(package_manager_.get());
if (compose_pacman == nullptr) {
Expand All @@ -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());
}

Expand Down
2 changes: 1 addition & 1 deletion src/liteclient.h
Original file line number Diff line number Diff line change
Expand Up @@ -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<HttpClient>& http_client, const Uptane::Target& target,
Expand Down
5 changes: 4 additions & 1 deletion src/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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) {
Expand All @@ -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) {
Expand Down

0 comments on commit dc22210

Please sign in to comment.