From 4c2e99ae8d99d2d1feb7e7ca2fcf1a8eefc75e90 Mon Sep 17 00:00:00 2001 From: Artem Grinev Date: Sat, 27 Apr 2024 15:50:59 +0000 Subject: [PATCH] fix(daemon): export symlinks to the box structure --- .../persistence/box/export/AlpmDBExporter.cpp | 49 +++++++++++++++++-- 1 file changed, 45 insertions(+), 4 deletions(-) diff --git a/daemon/persistence/box/export/AlpmDBExporter.cpp b/daemon/persistence/box/export/AlpmDBExporter.cpp index c9c67088..a1814315 100644 --- a/daemon/persistence/box/export/AlpmDBExporter.cpp +++ b/daemon/persistence/box/export/AlpmDBExporter.cpp @@ -23,12 +23,36 @@ #include #include #include +#include #include #include #include namespace bxt::Persistence::Box { +void create_relative_symlink(const std::filesystem::path& target, + const std::filesystem::path& link) { + if (std::filesystem::is_symlink(link)) { return; } + std::error_code ec; + const auto relative_target = + std::filesystem::relative(target, link.parent_path(), ec); + + if (ec) { + logf("Failed to get relative symlink path. The error is \"{}\". Box " + "will be malformed, exiting.", + ec.message()); + exit(1); + } + + std::filesystem::create_symlink(relative_target, link, ec); + if (ec) { + logf("Failed to create symlink. The error is \"{}\". Box will be " + "malformed, exiting.", + ec.message()); + exit(1); + } +} + AlpmDBExporter::AlpmDBExporter( BoxOptions& box_options, PackageStoreBase& package_store, @@ -98,12 +122,29 @@ coro::task AlpmDBExporter::export_to_disk() { "Exporter: Description for \"{}/{}-{}\" is being added... ", std::string(section), name, *version); + const auto preferred_description = package.descriptions.at( + *Core::Domain::select_preferred_pool_location( + package.descriptions)); + Utilities::AlpmDb::DatabaseUtils::write_buffer_to_archive( *writer, fmt::format("{}-{}/desc", name, *version), - package.descriptions - .at(*Core::Domain::select_preferred_pool_location( - package.descriptions)) - .descfile.desc); + preferred_description.descfile.desc); + + const auto filepath_link = std::filesystem::absolute( + m_box_path / std::string(section) + / preferred_description.filepath.filename()); + + create_relative_symlink(preferred_description.filepath, + filepath_link); + + if (preferred_description.signature_path) { + const auto signature_link = std::filesystem::absolute( + m_box_path / std::string(section) + / preferred_description.signature_path->filename()); + + create_relative_symlink( + *preferred_description.signature_path, signature_link); + } logd("Exporter: Description for \"{}/{}-{}\" is added", std::string(section), name, *version);