Skip to content

Commit

Permalink
fix(daemon): fix pool storage logic on update
Browse files Browse the repository at this point in the history
Resolves #100
  • Loading branch information
LordTermor committed Aug 8, 2024
1 parent 65d18fd commit a612baf
Showing 1 changed file with 23 additions and 9 deletions.
32 changes: 23 additions & 9 deletions daemon/persistence/box/store/LMDBPackageStore.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -139,34 +139,48 @@ coro::task<std::expected<void, DatabaseError>>
co_return bxt::make_error<DatabaseError>(
DatabaseError::ErrorType::InvalidArgument);
}
auto moved_package = m_pool.move_to(package);
auto moved_package_path = m_pool.path_for_package(package);

if (!moved_package.has_value()) {
if (!moved_package_path.has_value()) {
co_return bxt::make_error_with_source<DatabaseError>(
std::move(moved_package.error()),
std::move(moved_package_path.error()),
DatabaseError::ErrorType::InvalidArgument);
}

const auto key = package.id.to_string();

auto existing_package = co_await m_db.get(lmdb_uow->txn().value, key);
if (existing_package.has_value()) {
for (const auto& [location, desc] : moved_package->descriptions) {
existing_package->descriptions[location] = desc;
auto merged_package = *existing_package;
for (const auto& [location, desc] : moved_package_path->descriptions) {
merged_package.descriptions[location] = desc;
}
moved_package = *existing_package;
moved_package_path = merged_package;
}

auto result = co_await m_db.put(lmdb_uow->txn().value, key, *moved_package);
auto result =
co_await m_db.put(lmdb_uow->txn().value, key, *moved_package_path);

if (!result.has_value()) {
co_return bxt::make_error_with_source<DatabaseError>(
std::move(result.error()),
DatabaseError::ErrorType::InvalidArgument);
}

// auto mark = m_archiver.mark_dirty_sections({section});
// co_await mark;
lmdb_uow->hook([this, package, moved_package_path, existing_package] {
auto tmp_package = package;
for (const auto& desc : moved_package_path->descriptions) {
if (package.descriptions.contains(desc.first)
&& existing_package->descriptions.contains(desc.first)
&& desc.second.filepath
== existing_package->descriptions.at(desc.first)
.filepath) {
tmp_package.descriptions.erase(desc.first);
}
}

m_pool.move_to(std::move(tmp_package));
});

co_return {};
}
Expand Down

0 comments on commit a612baf

Please sign in to comment.