feat(update): fix schema-3 verify-before-parse and add replay floor, TrustStore, pin pruning, and InstallCoordinator
This commit is contained in:
1 parent
00d7478335
commit
47736cb6ce
13 files changed
+2663
-23
No files matched your search
@@ -1721,6 +1721,124 @@ namespace Void::Update
|
||||
return removed;
|
||||
}
|
||||
|
||||
Void::Result::Result<PruneReport>
|
||||
VersionStore::pruneWithPins(std::size_t retainedPreviousVersions,
|
||||
std::span<const Semver::Version>
|
||||
pinnedVersions,
|
||||
std::size_t batchLimit)
|
||||
{
|
||||
if (batchLimit == 0) {
|
||||
return Void::Result::fail(
|
||||
"VersionStore::pruneWithPins: batchLimit must be positive");
|
||||
}
|
||||
for (const auto& path : {m_root, m_root / "versions"}) {
|
||||
if (auto checked = require_real_directory(path); !checked) {
|
||||
return std::unexpected{checked.error()};
|
||||
}
|
||||
}
|
||||
auto lock = FileLock::acquire(m_root / ".update.lock");
|
||||
if (!lock) {
|
||||
return std::unexpected{lock.error()};
|
||||
}
|
||||
if (auto cleaned = cleanup_pruning_entries(m_root / "versions");
|
||||
!cleaned) {
|
||||
return std::unexpected{cleaned.error()};
|
||||
}
|
||||
|
||||
auto current = currentVersion();
|
||||
if (!current) {
|
||||
return std::unexpected{current.error()};
|
||||
}
|
||||
auto pending = pendingActivation();
|
||||
if (!pending) {
|
||||
return std::unexpected{pending.error()};
|
||||
}
|
||||
auto history = read_health_history(m_root);
|
||||
if (!history) {
|
||||
return std::unexpected{history.error()};
|
||||
}
|
||||
auto published = published_versions(m_root / "versions");
|
||||
if (!published) {
|
||||
return std::unexpected{published.error()};
|
||||
}
|
||||
|
||||
std::sort(published->begin(), published->end(),
|
||||
std::greater<Semver::Version>{});
|
||||
std::set<std::string, std::less<>> publishedNames;
|
||||
for (const auto& version : *published) {
|
||||
publishedNames.insert(version.to_string());
|
||||
}
|
||||
|
||||
std::set<std::string, std::less<>> retained;
|
||||
std::optional<std::string> currentName;
|
||||
if (*current) {
|
||||
currentName = (**current).to_string();
|
||||
retained.insert(*currentName);
|
||||
}
|
||||
if (*pending) {
|
||||
retained.insert((*pending)->candidateVersion.to_string());
|
||||
if ((*pending)->previousVersion) {
|
||||
retained.insert((*pending)->previousVersion->to_string());
|
||||
}
|
||||
}
|
||||
|
||||
std::size_t retainedPrevious = 0;
|
||||
for (auto iterator = history->committedOrder.rbegin();
|
||||
iterator != history->committedOrder.rend() &&
|
||||
retainedPrevious < retainedPreviousVersions;
|
||||
++iterator) {
|
||||
const auto state = history->states.find(*iterator);
|
||||
if (publishedNames.contains(*iterator) &&
|
||||
state != history->states.end() &&
|
||||
state->second == HealthState::healthy &&
|
||||
(!currentName || *iterator != *currentName) &&
|
||||
!retained.contains(*iterator)) {
|
||||
retained.insert(*iterator);
|
||||
++retainedPrevious;
|
||||
}
|
||||
}
|
||||
|
||||
std::set<std::string, std::less<>> pinnedNames;
|
||||
for (const auto& v : pinnedVersions) {
|
||||
pinnedNames.insert(v.to_string());
|
||||
}
|
||||
|
||||
PruneReport report;
|
||||
for (const auto& version : *published) {
|
||||
const auto name = version.to_string();
|
||||
if (retained.contains(name)) {
|
||||
continue;
|
||||
}
|
||||
const auto state = history->states.find(name);
|
||||
if (state == history->states.end() ||
|
||||
(state->second != HealthState::healthy &&
|
||||
state->second != HealthState::failed &&
|
||||
state->second != HealthState::retired)) {
|
||||
continue;
|
||||
}
|
||||
if (pinnedNames.contains(name)) {
|
||||
report.skipped_due_to_pins.push_back(version);
|
||||
continue;
|
||||
}
|
||||
if (report.removed.size() >= batchLimit) {
|
||||
report.batch_limit_reached = true;
|
||||
break;
|
||||
}
|
||||
if (state->second != HealthState::retired) {
|
||||
if (auto recorded = append_health_event(m_root, 'D', name);
|
||||
!recorded) {
|
||||
return std::unexpected{recorded.error()};
|
||||
}
|
||||
}
|
||||
if (auto pruned = quarantine_and_remove(m_root / "versions", name);
|
||||
!pruned) {
|
||||
return std::unexpected{pruned.error()};
|
||||
}
|
||||
report.removed.push_back(version);
|
||||
}
|
||||
return report;
|
||||
}
|
||||
|
||||
Void::Result::Result<std::optional<Semver::Version>>
|
||||
VersionStore::currentVersion() const
|
||||
{
|
||||
|
||||
Reference in new issue
Block a user