This repository has been archived by the owner on May 21, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 61
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add a simple autoclean feature for aktualizr daemon
Put it in a separate source so it can be more easily tested and won't pollute aktualizr_primary's main too much. Signed-off-by: Laurent Bonnans <[email protected]>
- Loading branch information
Showing
6 changed files
with
109 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#include "aktualizr_helpers.h" | ||
|
||
void targets_autoclean_cb(Aktualizr &aktualizr, const std::shared_ptr<event::BaseEvent> &event) { | ||
if (!event->isTypeOf<event::AllInstallsComplete>()) { | ||
return; | ||
} | ||
|
||
const auto targets_event = dynamic_cast<event::AllInstallsComplete *>(event.get()); | ||
|
||
std::vector<Uptane::Target> installed_targets = aktualizr.GetStoredTargets(); | ||
std::vector<bool> to_remove(installed_targets.size(), true); | ||
|
||
// do not remove targets that were just installed | ||
for (const result::Install::EcuReport &er : targets_event->result.ecu_reports) { | ||
const Uptane::Target t = er.update; | ||
auto it = std::find_if(installed_targets.begin(), installed_targets.end(), | ||
[&t](const Uptane::Target &t2) { return t.sha256Hash() == t2.sha256Hash(); }); | ||
if (it == installed_targets.end()) { | ||
continue; | ||
} | ||
|
||
size_t rem_idx = static_cast<size_t>(it - installed_targets.begin()); | ||
to_remove[rem_idx] = false; | ||
} | ||
|
||
// TODO: more specific check | ||
|
||
for (size_t k = 0; k < installed_targets.size(); k++) { | ||
if (to_remove[k]) { | ||
aktualizr.DeleteStoredTarget(installed_targets[k]); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#ifndef AKTUALIZR_HELPERS_H_ | ||
#define AKTUALIZR_HELPERS_H_ | ||
|
||
#include <memory> | ||
#include "aktualizr.h" | ||
|
||
// add as a signal handler to remove old targets just after an installation | ||
// completes | ||
void targets_autoclean_cb(Aktualizr &aktualizr, const std::shared_ptr<event::BaseEvent> &event); | ||
|
||
#endif // AKTUALIZR_HELPERS_H_ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters