Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

dnfdaemon: Support to run transactions offline #1543

Merged
merged 5 commits into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion dnf5/commands/offline/offline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,8 @@ void OfflineSubcommand::configure() {
const std::filesystem::path installroot = ctx.get_base().get_config().get_installroot_option().get_value();
datadir = installroot / libdnf5::offline::DEFAULT_DATADIR.relative_path();
std::filesystem::create_directories(datadir);
state = std::make_optional<libdnf5::offline::OfflineTransactionState>(datadir / "offline-transaction-state.toml");
state = std::make_optional<libdnf5::offline::OfflineTransactionState>(
datadir / libdnf5::offline::TRANSACTION_STATE_FILENAME);
}

void check_state(const libdnf5::offline::OfflineTransactionState & state) {
Expand Down
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

namespace dnfdaemon::client {

void TransactionCommand::run_transaction() {
void TransactionCommand::run_transaction(bool offline) {
auto & ctx = get_context();
dnfdaemon::KeyValueMap options = {};

Expand Down Expand Up @@ -80,6 +80,7 @@ void TransactionCommand::run_transaction() {

// do the transaction
options.clear();
options["offline"] = offline;
ctx.session_proxy->callMethod("do_transaction")
.onInterface(dnfdaemon::INTERFACE_GOAL)
.withTimeout(static_cast<uint64_t>(-1))
Expand Down
2 changes: 1 addition & 1 deletion dnf5daemon-client/commands/command.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class DaemonCommand : public libdnf5::cli::session::Command {
class TransactionCommand : public DaemonCommand {
public:
explicit TransactionCommand(Context & context, const std::string & name) : DaemonCommand(context, name){};
void run_transaction();
void run_transaction(bool offline = false);
};


Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/distro-sync/distro-sync.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void DistroSyncCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED, pkg_specs);
specs_arg->set_description("Patterns");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void DistroSyncCommand::run() {
Expand All @@ -65,7 +68,7 @@ void DistroSyncCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/distro-sync/distro-sync.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class DistroSyncCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs;
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/downgrade/downgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void DowngradeCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs);
specs_arg->set_description("List of packages to downgrade");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void DowngradeCommand::run() {
Expand All @@ -65,7 +68,7 @@ void DowngradeCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/downgrade/downgrade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class DowngradeCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/install/install.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,9 @@ void InstallCommand::set_argument_parser() {
skip_unavailable->link_value(&skip_unavailable_option);
cmd.register_named_arg(skip_unavailable);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);

auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs);
specs_arg->set_description("List of packages to install");
cmd.register_positional_arg(specs_arg);
Expand All @@ -88,7 +91,7 @@ void InstallCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
4 changes: 2 additions & 2 deletions dnf5daemon-client/commands/install/install.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {
Expand All @@ -35,9 +34,10 @@ class InstallCommand : public TransactionCommand {
void run() override;

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool skip_broken_option{false};
libdnf5::OptionBool skip_unavailable_option{false};
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/reinstall/reinstall.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void ReinstallCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::AT_LEAST_ONE, pkg_specs);
specs_arg->set_description("List of packages to reinstall");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void ReinstallCommand::run() {
Expand All @@ -65,7 +68,7 @@ void ReinstallCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/reinstall/reinstall.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class ReinstallCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
5 changes: 4 additions & 1 deletion dnf5daemon-client/commands/remove/remove.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ void RemoveCommand::set_argument_parser() {
specs_arg->set_description("List of packages to remove");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);

// run remove command always with allow_erasing on
context.allow_erasing.set(libdnf5::Option::Priority::RUNTIME, true);
}
Expand All @@ -69,7 +72,7 @@ void RemoveCommand::run() {
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/remove/remove.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class RemoveCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
20 changes: 20 additions & 0 deletions dnf5daemon-client/commands/shared_options.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,12 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "utils/url.hpp"

#include <libdnf5-cli/argument_parser.hpp>

#include <filesystem>

namespace {

static void normalize_paths(int specs_count, const char * const specs[], std::vector<std::string> & pkg_specs) {
const std::string_view ext(".rpm");
std::set<std::string_view> unique_items;
Expand All @@ -39,6 +43,10 @@ static void normalize_paths(int specs_count, const char * const specs[], std::ve
}
}

} // anonymous namespace

namespace dnfdaemon::client {

libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument(
libdnf5::cli::ArgumentParser & parser, int nargs, std::vector<std::string> & pkg_specs) {
auto specs = parser.add_new_positional_arg("pkg_specs", nargs, nullptr, nullptr);
Expand All @@ -49,3 +57,15 @@ libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument(
});
return specs;
}

libdnf5::cli::ArgumentParser::NamedArg * create_offline_option(
libdnf5::cli::ArgumentParser & parser, libdnf5::Option * value) {
auto offline = parser.add_new_named_arg("offline");
offline->set_long_name("offline");
offline->set_description("Store the transaction to be performed offline");
offline->set_const_value("true");
offline->link_value(value);
return offline;
}

} // namespace dnfdaemon::client
7 changes: 7 additions & 0 deletions dnf5daemon-client/commands/shared_options.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,14 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include <libdnf5-cli/argument_parser.hpp>

namespace dnfdaemon::client {

libdnf5::cli::ArgumentParser::PositionalArg * pkg_specs_argument(
libdnf5::cli::ArgumentParser & parser, int nargs, std::vector<std::string> & pkg_specs);

/// Create the `--offline` named arg bound to the given option
libdnf5::cli::ArgumentParser::NamedArg * create_offline_option(
libdnf5::cli::ArgumentParser & parser, libdnf5::Option * value);

} // namespace dnfdaemon::client
#endif
6 changes: 4 additions & 2 deletions dnf5daemon-client/commands/upgrade/upgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,9 @@ void UpgradeCommand::set_argument_parser() {
auto specs_arg = pkg_specs_argument(parser, libdnf5::cli::ArgumentParser::PositionalArg::UNLIMITED, pkg_specs);
specs_arg->set_description("List of packages to upgrade");
cmd.register_positional_arg(specs_arg);

auto offline_arg = create_offline_option(parser, &offline_option);
cmd.register_named_arg(offline_arg);
}

void UpgradeCommand::run() {
Expand All @@ -59,13 +62,12 @@ void UpgradeCommand::run() {
}

dnfdaemon::KeyValueMap options = {};

ctx.session_proxy->callMethod("upgrade")
.onInterface(dnfdaemon::INTERFACE_RPM)
.withTimeout(static_cast<uint64_t>(-1))
.withArguments(pkg_specs, options);

run_transaction();
run_transaction(offline_option.get_value());
}

} // namespace dnfdaemon::client
3 changes: 2 additions & 1 deletion dnf5daemon-client/commands/upgrade/upgrade.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.

#include "commands/command.hpp"

#include <libdnf5/conf/option.hpp>
#include <libdnf5/conf/option_bool.hpp>

namespace dnfdaemon::client {

Expand All @@ -35,6 +35,7 @@ class UpgradeCommand : public TransactionCommand {

private:
std::vector<std::string> pkg_specs{};
libdnf5::OptionBool offline_option{false};
};

} // namespace dnfdaemon::client
Expand Down
1 change: 1 addition & 0 deletions dnf5daemon-server/dbus.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ const char * const INTERFACE_RPM = "org.rpm.dnf.v0.rpm.Rpm";
const char * const INTERFACE_GOAL = "org.rpm.dnf.v0.Goal";
const char * const INTERFACE_GROUP = "org.rpm.dnf.v0.comps.Group";
const char * const INTERFACE_ADVISORY = "org.rpm.dnf.v0.Advisory";
const char * const INTERFACE_OFFLINE = "org.rpm.dnf.v0.Offline";
const char * const INTERFACE_SESSION_MANAGER = "org.rpm.dnf.v0.SessionManager";

// signals
Expand Down
2 changes: 2 additions & 0 deletions dnf5daemon-server/dbus/interfaces/org.rpm.dnf.v0.Goal.xml
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,8 @@ along with libdnf. If not, see <https://www.gnu.org/licenses/>.
Following @options are supported:
- comment: string
Adds a comment to a transaction.
- offline: boolean, default false
If true, the transaction will be prepared to run during the next reboot. Otherwise, it will run immediately.

Unknown options are ignored.
-->
Expand Down
Loading
Loading