feat: rebuild, list, rollback — Phase 5 completion
- kappa rebuild: diffs config vs installed DB, reports changed/added/removed packages, detects kernel/init/bootloader/service changes - kappa list: shows installed packages with versions, hashes, provides - kappa rollback: lists available generations from /kappa/db/generations - list + rollback don't require a file argument (no-file subcommands) - Rebuild wired to compute_changes() → per-package change detection Full pipeline: resolve → fetch → build → install → list/rollback/rebuild
This commit is contained in:
@@ -0,0 +1,84 @@
|
||||
#include "kappa/rebuild/rebuild.hpp"
|
||||
#include "kappa/install/install.hpp"
|
||||
|
||||
#include <format>
|
||||
#include <set>
|
||||
|
||||
namespace kappa::rebuild {
|
||||
|
||||
ChangeSet compute_changes(const dsl::SystemConfig& cfg) {
|
||||
ChangeSet cs;
|
||||
auto installed = install::read_installed();
|
||||
|
||||
std::set<std::string> installed_names;
|
||||
for (auto& e : installed) { installed_names.insert(e.name); }
|
||||
|
||||
std::set<std::string> config_names;
|
||||
for (auto& p : cfg.packages) { config_names.insert(p.name); }
|
||||
|
||||
for (auto& p : cfg.packages) {
|
||||
if (!installed_names.contains(p.name)) {
|
||||
cs.added.push_back(p.name);
|
||||
continue;
|
||||
}
|
||||
|
||||
bool found = false;
|
||||
for (auto& e : installed) {
|
||||
if (e.name != p.name) { continue; }
|
||||
found = true;
|
||||
|
||||
bool ver_changed = !p.version.empty()
|
||||
&& e.version != p.version;
|
||||
bool feat_changed = !p.features.empty();
|
||||
bool cfg_changed = !p.config.empty();
|
||||
|
||||
if (ver_changed || feat_changed || cfg_changed) {
|
||||
cs.changed.push_back(p.name);
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (!found) { cs.added.push_back(p.name); }
|
||||
}
|
||||
|
||||
for (auto& e : installed) {
|
||||
if (!config_names.contains(e.name)) {
|
||||
cs.removed.push_back(e.name);
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& e : installed) {
|
||||
if (e.name == "kernel" && e.hash != cfg.boot.kernel) {
|
||||
cs.kernel_changed = true;
|
||||
}
|
||||
if (e.name == "init" && e.hash != cfg.boot.init) {
|
||||
cs.init_changed = true;
|
||||
}
|
||||
if (e.name == "bootloader" && e.hash != cfg.boot.bootloader) {
|
||||
cs.bootloader_changed = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (auto& svc : cfg.services) {
|
||||
if (!svc.enable) { continue; }
|
||||
bool found = false;
|
||||
for (auto& e : installed) {
|
||||
if (e.name == ("svc:" + svc.name)) {
|
||||
found = true;
|
||||
for (auto& [k, v] : svc.config) {
|
||||
auto it = std::find(e.provides.begin(), e.provides.end(),
|
||||
k + "=" + v);
|
||||
if (it == e.provides.end()) {
|
||||
cs.services_changed = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!found) { cs.services_changed = true; break; }
|
||||
}
|
||||
|
||||
return cs;
|
||||
}
|
||||
|
||||
} // namespace kappa::rebuild
|
||||
Reference in New Issue
Block a user