From 30c769764e1863c07f3db50a34c2f0dc79ca12a2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Thu, 19 Sep 2024 05:31:01 -0400 Subject: [PATCH 1/2] Fix deserialization when checking signals `object_path` Since https://github.com/rpm-software-management/dnf5/pull/1679 `sdbus::ObjectPath` is send over to the client not std::string. This was causing the check `signature_valid(sdbus::Signal &)` to crash, the client callback ended and the server kept waiting for result of the `key_import` userconfirm. --- dnf5daemon-client/callbacks.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/dnf5daemon-client/callbacks.cpp b/dnf5daemon-client/callbacks.cpp index 5e66be388..e4e35d9bf 100644 --- a/dnf5daemon-client/callbacks.cpp +++ b/dnf5daemon-client/callbacks.cpp @@ -36,7 +36,7 @@ namespace dnfdaemon::client { bool DbusCallback::signature_valid(sdbus::Signal & signal) { // check that signal is emitted by the correct session object - std::string object_path; + sdbus::ObjectPath object_path; signal >> object_path; return object_path == context.get_session_object_path(); } From 8a447f4feef2a7871f76f89364e71f6a4bc534e6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ale=C5=A1=20Mat=C4=9Bj?= Date: Fri, 20 Sep 2024 02:28:38 -0400 Subject: [PATCH 2/2] dnf5daemon-server: Run transaction test for offline transactions A serialized offline transaction consists only of local packages downloaded to the `/offline` location. Unfortunately, PGP checks for these packages are disabled by default due to the `localpkg_gpgcheck` option default value. Instead of testing the serialized transaction, this patch performs an RPM transaction test on the originally resolved transaction, which still retains information about the repositories from which the packages were downloaded. This approach also saves time required for deserialization and resolving the testing transaction. This ports the fix from https://github.com/rpm-software-management/dnf5/pull/1672 to dnf5daemon. --- dnf5daemon-server/session.cpp | 36 +++++++++++++++-------------------- 1 file changed, 15 insertions(+), 21 deletions(-) diff --git a/dnf5daemon-server/session.cpp b/dnf5daemon-server/session.cpp index 1a31530e0..cd18f5685 100644 --- a/dnf5daemon-server/session.cpp +++ b/dnf5daemon-server/session.cpp @@ -308,6 +308,7 @@ void Session::download_transaction_packages() { } void Session::store_transaction_offline() { + // Download transaction packages const auto & installroot = base->get_config().get_installroot_option().get_value(); const auto & dest_dir = installroot / libdnf5::offline::DEFAULT_DATADIR.relative_path() / "packages"; std::filesystem::create_directories(dest_dir); @@ -315,6 +316,20 @@ void Session::store_transaction_offline() { download_transaction_packages(); set_cancel_download(Session::CancelDownload::NOT_ALLOWED); + // Test the transaction + // TODO(mblaha): store transaction test/run problems in the session and add an API + // to retrieve it + base->get_config().get_tsflags_option().set(libdnf5::Option::Priority::RUNTIME, "test"); + auto result = transaction->run(); + if (result != libdnf5::base::Transaction::TransactionRunResult::SUCCESS) { + throw sdbus::Error( + dnfdaemon::ERROR_TRANSACTION, + fmt::format( + "offline rpm transaction test failed with code {}.", + static_cast>(result))); + } + + // Serialize the transaction const auto & offline_datadir = installroot / libdnf5::offline::DEFAULT_DATADIR.relative_path(); std::filesystem::create_directories(offline_datadir); @@ -330,7 +345,6 @@ void Session::store_transaction_offline() { state_data.set_status(libdnf5::offline::STATUS_DOWNLOAD_INCOMPLETE); state.write(); - // First, serialize the transaction transaction->store_comps(comps_location); const auto transaction_json_path = offline_datadir / "transaction.json"; @@ -338,26 +352,6 @@ void Session::store_transaction_offline() { transaction_json_file.write(transaction->serialize(packages_in_trans_dir, comps_in_trans_dir)); transaction_json_file.close(); - // Then, test the serialized transaction - // TODO(mblaha): store transaction test/run problems in the session and add an API - // to retrieve it - const auto & test_goal = std::make_unique(*base); - test_goal->add_serialized_transaction(transaction_json_path); - auto test_transaction = test_goal->resolve(); - if (test_transaction.get_problems() != libdnf5::GoalProblem::NO_PROBLEM) { - throw sdbus::Error(dnfdaemon::ERROR_TRANSACTION, "failed to resolve serialized offline transaction."); - } - base->get_config().get_tsflags_option().set(libdnf5::Option::Priority::RUNTIME, "test"); - - auto result = test_transaction.run(); - if (result != libdnf5::base::Transaction::TransactionRunResult::SUCCESS) { - throw sdbus::Error( - dnfdaemon::ERROR_TRANSACTION, - fmt::format( - "offline rpm transaction test failed with code {}.", - static_cast>(result))); - } - // Download and transaction test complete. Fill out entries in offline // transaction state file. state_data.set_cachedir(base->get_config().get_cachedir_option().get_value());