libdnf5::base
-
enum class libdnf5::base::TransactionPersistence : int
Values:
-
enumerator UNKNOWN
-
enumerator PERSIST
-
enumerator TRANSIENT
-
enumerator UNKNOWN
-
typedef WeakPtr<VendorChangeManager, false> libdnf5::base::VendorChangeManagerWeakPtr
-
constexpr int32_t libdnf5::base::ANSWER_YES = -1
Return value constants for InteractionCallbacks confirm(), choice(), and input_text() methods.
User confirmed / a string entered
-
constexpr int32_t libdnf5::base::ANSWER_NO = -2
User denied / undefined string.
-
constexpr int32_t libdnf5::base::ANSWER_DEFAULT = -3
Use the caller-supplied default.
-
constexpr int32_t libdnf5::base::ANSWER_ABORT = -4
Abort the operation (user request or I/O error).
-
class ActiveTransactionInfo
Public Functions
-
ActiveTransactionInfo()
-
ActiveTransactionInfo(const ActiveTransactionInfo&)
-
ActiveTransactionInfo(ActiveTransactionInfo&&) noexcept
-
ActiveTransactionInfo &operator=(const ActiveTransactionInfo&)
-
ActiveTransactionInfo &operator=(ActiveTransactionInfo&&) noexcept
-
~ActiveTransactionInfo()
-
const std::string &get_description() const noexcept
Get the transaction description.
- Returns:
Description string
-
const std::string &get_comment() const noexcept
Get the transaction comment.
- Returns:
Comment string
-
pid_t get_pid() const noexcept
Get the process ID of the transaction.
- Returns:
Process ID, or -1 if not available
-
time_t get_start_time() const noexcept
Get the transaction start time as Unix timestamp.
- Returns:
Unix timestamp (seconds since epoch), or 0 if not available
-
void set_description(const std::string &description)
-
void set_comment(const std::string &comment)
-
void set_pid(pid_t pid)
-
void set_start_time(time_t start_time)
-
std::string to_toml() const
Convert ActiveTransactionInfo to TOML string format.
- Throws:
std::runtime_error – if TOML formatting fails
- Returns:
TOML formatted string representation
Public Static Functions
-
static ActiveTransactionInfo from_toml(const std::string &toml_string)
Create ActiveTransactionInfo from TOML string.
- Parameters:
toml_string – The TOML string to parse
- Throws:
ActiveTransactionInfoParseError – if TOML parsing fails
- Returns:
ActiveTransactionInfo object parsed from TOML
-
ActiveTransactionInfo()
-
class ActiveTransactionInfoParseError : public libdnf5::Error
Public Functions
-
inline virtual const char *get_domain_name() const noexcept override
- Returns:
The domain name (namespace and enclosing class names) of the exception.
-
inline virtual const char *get_name() const noexcept override
- Returns:
The exception class name.
-
template<AllowedErrorArgTypes... Args>
inline explicit Error(BgettextMessage format, Args... args) A constructor that supports formatting the error message.
- Parameters:
format – The format string for the message.
args – The format arguments.
-
template<AllNamedErrorArgs... RestArgs>
inline explicit Error(BgettextMessage format, NamedErrorArg first_arg, RestArgs... rest_args) A constructor that supports formatting the error message with NamedErrorArg arguments. Requires AT LEAST ONE named argument (FirstArg) to avoid ambiguity with the zero-argument original constructor.
- Parameters:
format – The format string for the message.
first_arg – The first named format argument.
rest_args – Additional named format arguments.
-
inline virtual const char *get_domain_name() const noexcept override
-
class InteractionCallbacks
- #include <interaction_callbacks.hpp>
Base class for interaction callbacks. To implement callbacks, inherit from this class and override virtual methods.
These callbacks allow libdnf5 plugins to interact with the user through the application. The application implements these methods to provide user interface for messages, confirmations, choices, text input, and progress.
Public Types
Public Functions
-
explicit InteractionCallbacks()
-
InteractionCallbacks(const InteractionCallbacks&) = delete
-
InteractionCallbacks(InteractionCallbacks&&) = delete
-
virtual ~InteractionCallbacks()
-
InteractionCallbacks &operator=(const InteractionCallbacks&) = delete
-
InteractionCallbacks &operator=(InteractionCallbacks&&) = delete
Friends
- friend class ::libdnf5::Base
-
explicit InteractionCallbacks()
-
class LogEvent
- #include <log_event.hpp>
Contain information, hint, or a problem created during libdnf5::Goal::resolve().
Public Functions
-
LogEvent(libdnf5::GoalAction action, libdnf5::GoalProblem problem, const std::set<std::string> &additional_data, const libdnf5::GoalJobSettings &settings, const libdnf5::transaction::TransactionItemType spec_type, const std::string &spec)
Public constructor.
-
LogEvent(libdnf5::GoalProblem problem, const SolverProblems &solver_problems)
-
~LogEvent()
-
libdnf5::GoalAction get_action() const
- Returns:
GoalAction for which goal event was created
-
libdnf5::GoalProblem get_problem() const
- Returns:
GoalProblem that specify the type of report
-
const std::set<std::string> &get_additional_data() const
- Returns:
Additional information (internal), that are required for formatted string
-
const libdnf5::GoalJobSettings *get_job_settings() const
- Returns:
GoalJobSetting if it is relevant for the particular GoalProblem
-
const std::string *get_spec() const
- Returns:
SPEC if it is relevant for the particular GoalProblem
-
const SolverProblems *get_solver_problems() const
- Returns:
SolverProblems if they are relevant for the particular GoalProblem
-
std::string to_string() const
Convert an element from resolve log to string;.
-
LogEvent(libdnf5::GoalAction action, libdnf5::GoalProblem problem, const std::set<std::string> &additional_data, const libdnf5::GoalJobSettings &settings, const libdnf5::transaction::TransactionItemType spec_type, const std::string &spec)
-
class SolverProblems
- #include <solver_problems.hpp>
Represent problems detected by a RPM solver (libsolv).
Public Functions
-
SolverProblems(const std::vector<std::vector<std::pair<libdnf5::ProblemRules, std::vector<std::string>>>> &problems)
Public constructor.
-
SolverProblems(const SolverProblems &src)
-
SolverProblems(SolverProblems &&src) noexcept
-
SolverProblems &operator=(const SolverProblems &src)
-
SolverProblems &operator=(SolverProblems &&src) noexcept
-
~SolverProblems()
-
std::vector<std::vector<std::pair<libdnf5::ProblemRules, std::vector<std::string>>>> get_problems() const
Provide information about package solver problems in a vector. Each problem can be transformed to string by package_solver_problem_to_string or all problems to a string by all_package_solver_problems_to_string().
- Returns:
Vector of problems encountered by the solver. Each problem is described by a vector of “rule breakages” (TODO(lukash) try to find a better name for this) stored in a
std::pair<libdnf5::ProblemRules, std::vector<std::string>>, where the first of the pair is a rule breakage identifier and the second is a list of string identifiers which are the subjects of the rule breakage. These can be rendered into a string by theproblem_to_string()method.
-
std::string to_string() const
Convert SolverProblems class to string representative;.
Public Static Functions
-
static std::string problem_to_string(const std::pair<libdnf5::ProblemRules, std::vector<std::string>> &raw)
Convert particular package solver problem to a string;.
-
SolverProblems(const std::vector<std::vector<std::pair<libdnf5::ProblemRules, std::vector<std::string>>>> &problems)
-
class TextValidator
- #include <text_validator.hpp>
Created by Base, wrapping the caller’s TextValidatorCallback. Overrides must not construct this class directly.
Public Functions
-
TextValidator() = delete
-
TextValidator(const TextValidator&) = delete
-
TextValidator(TextValidator&&) = delete
-
TextValidator &operator=(const TextValidator&) = delete
-
TextValidator &operator=(TextValidator&&) = delete
-
libdnf5::Message *validate(const std::string &input)
Validate text input by delegating to the underlying TextValidatorCallback.
- Returns:
nullptr if the input is valid, or a Message with an error description if invalid.
Friends
- friend class ::libdnf5::Base
-
TextValidator() = delete
-
class TextValidatorCallback
- #include <text_validator_callback.hpp>
Input validator callback interface for text input validation. Plugins can implement custom validators by inheriting from this class.
Public Functions
-
TextValidatorCallback()
-
TextValidatorCallback(const TextValidatorCallback&) = delete
-
TextValidatorCallback &operator=(const TextValidatorCallback&) = delete
-
virtual ~TextValidatorCallback()
-
TextValidatorCallback()
-
class Transaction
Public Types
Public Functions
-
Transaction(const Transaction &transaction)
-
Transaction(Transaction &&transaction)
-
~Transaction()
-
libdnf5::GoalProblem get_problems()
Return basic overview about result of resolving transaction. To get complete information, use get_resolve_logs().
-
const std::vector<libdnf5::base::LogEvent> &get_resolve_logs() const
Returns information about resolvement of Goal.
- Returns:
A vector of LogEvent instances.
-
std::vector<std::string> get_resolve_logs_as_strings() const
Returns information about resolvement of Goal as a list of printable messages
- Returns:
A vector of string representations of problems.
-
std::vector<libdnf5::base::TransactionPackage> get_transaction_packages() const
- Returns:
the transaction packages.
-
std::size_t get_transaction_packages_count() const
- Returns:
the number of transaction packages.
-
std::vector<libdnf5::base::TransactionGroup> &get_transaction_groups() const
- Returns:
the transaction groups.
-
std::vector<libdnf5::base::TransactionModule> &get_transaction_modules() const
- Returns:
the transaction modules.
-
std::vector<libdnf5::base::TransactionEnvironment> &get_transaction_environments() const
- Returns:
environmental groups that are part of the transaction.
-
std::vector<libdnf5::rpm::Package> get_broken_dependency_packages() const
- Returns:
list of packages skipped due to broken dependencies
-
std::vector<libdnf5::rpm::Package> get_conflicting_packages() const
- Returns:
list of packages skipped due to conflicts
-
const std::vector<std::pair<libdnf5::rpm::Package, std::string>> &get_vendor_change_skipped_packages() const
- Returns:
list of packages skipped due to vendor change restriction, paired with installed vendor string
-
bool empty() const
- Returns:
trueif the transaction is empty.
-
void download()
Download all inbound packages (packages that are being installed on the system). Fails immediately on the first package download failure. Will try to resume downloads of any partially-downloaded RPMs.
The destination directory for downloaded RPMs is taken from the
destdirconfiguration option. If it’s not specified, the standard location of repo cachedir/packages is used.
-
TransactionRunResult test()
Check the transaction by running it with RPMTRANS_FLAG_TEST. The import of any necessary public keys will be requested, and transaction checks will be performed, but no changes to the installed package set will be made. These checks are performed automatically by run(); it is redundant to call test() before calling run().
- Returns:
An enum describing the result of the transaction
-
TransactionRunResult run()
Prepare, check and run the transaction.
All the transaction metadata that was set (
description,user_idorcomment) is stored in the history database.To watch progress or trigger actions during specific transactions events, setup the
callbacksobject.After a successful transaction, any temporarily downloaded packages are removed if the ‘keepcache’ option is set to ‘false’ and the transaction involved an inbound action. Otherwise, the packages are preserved on the disk.
- Returns:
An enum describing the result of running the transaction.
-
void set_callbacks(std::unique_ptr<libdnf5::rpm::TransactionCallbacks> &&callbacks)
Setup callbacks to be called during rpm transaction.
- Parameters:
callbacks – Implemented callbacks object.
-
void set_description(const std::string &description)
Setup a description of the transaction.
- Parameters:
description – Value could be the console command for CLI or verbose description for API usage.
-
void set_user_id(const uint32_t user_id)
Setup the id of the user that started the transaction. If not set, current login user UID is used.
- Parameters:
user_id – UID value.
-
void set_comment(const std::string &comment)
Setup a comment to store in the history database along with the transaction.
- Parameters:
comment – Any string value.
-
void set_persistence(libdnf5::base::TransactionPersistence persistence)
Setup the persistence of the transaction (persist or transient).
- Parameters:
persistence – TransactionPersistence value.
-
std::vector<std::string> get_transaction_problems() const noexcept
Retrieve list of problems that occurred during transaction run attempt.
-
bool check_gpg_signatures()
Check signatures of packages in the resolved transaction.
- Returns:
True if all packages have correct signatures or checking is turned off with
pkg_gpgcheckoption, otherwise false. More info about occurred problems can be retrieved using theget_gpg_signature_problemsmethod.
-
std::vector<std::string> get_gpg_signature_problems() const noexcept
Retrieve a list of the problems that occurred during
check_gpg_signaturesprocedure.
-
std::string serialize(const std::filesystem::path &packages_path = "", const std::filesystem::path &comps_path = "", const std::string repo_prefix = "") const
Warning
This method is experimental/unstable and should not be relied on. It may be removed without warning Serialize the transaction into a json data format which can be later loaded into a
libdnf5::Goaland replayed.- Parameters:
packages_path – If provided it is assumed all packages in this transaction are present there and the resulting serialized transaction will contain paths to those packages.
comps_path – If provided it is assumed all comps in this transaction are present there and the resulting serialized transaction will contain paths to those xml comps files (they can be stored using the
store_compsmethod).repo_prefix – If provided each repository id (except for @System repo) used in this transaction will be wrapped in brackets and prefix by repo_prefix.
-
void store_comps(const std::filesystem::path &comps_path) const
Warning
This method is experimental/unstable and should not be relied on. It may be removed without warning Store each group and environment in this transaction as a separate xml file in the specified path.
-
void set_download_local_pkgs(bool value)
Set whether local packages should be copied to the destination directory during the download().
Default: false
-
bool get_download_local_pkgs() const noexcept
-
std::string get_last_script_output()
Retrieve output of the last executed rpm scriptlet.
-
std::vector<std::string> get_rpm_messages()
Retrieve captured RPM log messages.
-
const ActiveTransactionInfo *get_concurrent_transaction() const noexcept
Retrieve metadata of concurrently running transaction.
Public Static Functions
-
static std::string transaction_result_to_string(const TransactionRunResult result)
Return string representation of the TransactionRunResult enum.
Friends
- friend class libdnf5::Goal
- friend class libdnf5::rpm::Transaction
-
Transaction(const Transaction &transaction)
-
class TransactionEnvironment
Public Types
-
using Reason = transaction::TransactionItemReason
-
using State = transaction::TransactionItemState
-
using Action = transaction::TransactionItemAction
Public Functions
-
libdnf5::comps::Environment get_environment() const
- Returns:
the underlying environment.
-
Action get_action() const noexcept
- Returns:
the action being performed on the transaction environment.
-
Reason get_reason() const noexcept
- Returns:
the reason of the action being performed on the transaction environment.
-
bool get_with_optional() const noexcept
- Returns:
package types requested to be installed with the group.
-
~TransactionEnvironment()
-
TransactionEnvironment(const TransactionEnvironment &mpkg)
-
TransactionEnvironment &operator=(const TransactionEnvironment &mpkg)
-
TransactionEnvironment(TransactionEnvironment &&mpkg) noexcept
-
TransactionEnvironment &operator=(TransactionEnvironment &&mpkg) noexcept
Friends
- friend class Transaction::Impl
-
using Reason = transaction::TransactionItemReason
-
class TransactionError : public libdnf5::Error
- #include <transaction_errors.hpp>
Error related to processing transaction.
Public Functions
-
inline virtual const char *get_domain_name() const noexcept override
- Returns:
Error class’ domain name”
-
template<AllowedErrorArgTypes... Args>
inline explicit Error(BgettextMessage format, Args... args) A constructor that supports formatting the error message.
- Parameters:
format – The format string for the message.
args – The format arguments.
-
template<AllNamedErrorArgs... RestArgs>
inline explicit Error(BgettextMessage format, NamedErrorArg first_arg, RestArgs... rest_args) A constructor that supports formatting the error message with NamedErrorArg arguments. Requires AT LEAST ONE named argument (FirstArg) to avoid ambiguity with the zero-argument original constructor.
- Parameters:
format – The format string for the message.
first_arg – The first named format argument.
rest_args – Additional named format arguments.
-
inline virtual const char *get_domain_name() const noexcept override
-
class TransactionGroup
Public Types
-
using Reason = transaction::TransactionItemReason
-
using State = transaction::TransactionItemState
-
using Action = transaction::TransactionItemAction
-
using PackageType = libdnf5::comps::PackageType
Public Functions
-
libdnf5::comps::Group get_group() const
- Returns:
the underlying group.
-
Reason get_reason() const noexcept
- Returns:
the reason of the action being performed on the transaction group.
-
PackageType get_package_types() const noexcept
- Returns:
package types requested to be installed with the group.
-
~TransactionGroup()
-
TransactionGroup(const TransactionGroup &mpkg)
-
TransactionGroup &operator=(const TransactionGroup &mpkg)
-
TransactionGroup(TransactionGroup &&mpkg) noexcept
-
TransactionGroup &operator=(TransactionGroup &&mpkg) noexcept
Friends
- friend class Transaction::Impl
-
using Reason = transaction::TransactionItemReason
-
class TransactionModule
Public Types
-
using Reason = transaction::TransactionItemReason
-
using State = transaction::TransactionItemState
-
using Action = transaction::TransactionItemAction
Public Functions
-
std::string get_module_name() const
- Returns:
the module name.
-
std::string get_module_stream() const
- Returns:
the module stream.
-
Reason get_reason() const noexcept
- Returns:
the reason of the action being performed on the transaction module.
-
std::vector<std::pair<std::string, std::string>> get_replaces() const noexcept
- Returns:
module:stream pairs replaced by this transaction module.
-
const std::vector<std::pair<std::string, std::string>> &get_replaced_by() const noexcept
- Returns:
module:stream pairs that replace this transaction module (for transaction modules that are leaving the system).
-
~TransactionModule()
-
TransactionModule(const TransactionModule &mpkg)
-
TransactionModule &operator=(const TransactionModule &mpkg)
-
TransactionModule(TransactionModule &&mpkg) noexcept
-
TransactionModule &operator=(TransactionModule &&mpkg) noexcept
Friends
- friend class Transaction::Impl
-
using Reason = transaction::TransactionItemReason
-
class TransactionPackage
- #include <transaction_package.hpp>
Describe transaction operation related to rpm Package.
Public Types
-
using Action = transaction::TransactionItemAction
-
using Reason = transaction::TransactionItemReason
-
using State = transaction::TransactionItemState
Public Functions
-
libdnf5::rpm::Package get_package() const
- Returns:
the underlying package.
-
Reason get_reason() const noexcept
- Returns:
the reason of the action being performed on the transaction package.
-
std::vector<rpm::Package> get_replaces() const noexcept
- Returns:
packages replaced by this transaction package.
-
const std::vector<rpm::Package> &get_replaced_by() const noexcept
- Returns:
packages that replace this transaction package (for transaction packages that are leaving the system).
-
const std::string *get_reason_change_group_id() const noexcept
The REASON_CHANGE action requires group id in case the reason is changed to GROUP
- Returns:
id of group the package belongs to
-
~TransactionPackage()
-
TransactionPackage(const TransactionPackage &mpkg)
-
TransactionPackage &operator=(const TransactionPackage &mpkg)
-
TransactionPackage(TransactionPackage &&mpkg) noexcept
-
TransactionPackage &operator=(TransactionPackage &&mpkg) noexcept
Friends
- friend class Transaction::Impl
- friend class ::BaseGoalTest
- friend class ::RpmTransactionTest
-
using Action = transaction::TransactionItemAction
-
class VendorChangeManager
- #include <vendor_change_manager.hpp>
Manages vendor change policies that control which package vendor transitions are allowed.
Policies can be loaded from TOML configuration files (typically found in
/etc/dnf/vendors.d/and/usr/share/dnf5/vendors.d/) or from a compact string representation suitable for command-line use.Policies loaded from configuration files during :func:
Base::setup()are applied automatically. Additional policies can be added at runtime via this class.An instance is obtained from :func:
Base::get_vendor_change_manager()after :func:Base::setup()has been called.Public Functions
-
~VendorChangeManager()
-
VendorChangeManager(const VendorChangeManager&) = delete
-
VendorChangeManager &operator=(const VendorChangeManager&) = delete
-
VendorChangeManagerWeakPtr get_weak_ptr()
- Returns:
A weak pointer to this VendorChangeManager instance.
-
void load_policy_from_toml(std::string_view toml_content, std::string_view source)
Load a vendor change policy from TOML content. The content must conform to the vendor change policy format.
- Parameters:
toml_content – The TOML content to parse.
source – Origin of the policy (file URI or custom label with
text:prefix, e.g.,"text:COMMAND LINE"). Stored for diagnostics and logging.
- Throws:
VendorChangeManagerError – if the content cannot be parsed or contains invalid values.
-
void load_policy_from_toml(const std::filesystem::path &path)
Load one vendor change policy from a TOML configuration file. The file must conform to the vendor change policy format.
- Parameters:
path – Path to the TOML configuration file.
- Throws:
VendorChangeManagerError – if the file cannot be parsed or contains invalid values.
-
void load_policy_from_compact(std::string_view policy_str, std::string_view source)
Load a vendor change policy from a compact string representation.
The compact format is:
direction:eop"value",...@direction:e[filters],...Both sections (before and after
@) are optional, but at least one must be present. Vendor entries use direction prefixesin:,out:, oreq:followed by an optionale(exclude) flag and an operator with a quoted value. Package filter entries are enclosed in literal[...]after the@separator.Example:
eq:i^"Fedora",in:"Third Vendor"@in:[version>="2.0"]- Parameters:
policy_str – The compact policy string to parse.
source – Origin of the policy (file URI or custom label with
text:prefix, e.g.,"text:COMMAND LINE"). Stored for diagnostics and logging.
- Throws:
VendorChangeManagerError – if the string cannot be parsed.
-
std::size_t unload_policies()
Unload all vendor change policies from memory.
- Returns:
The number of policies that were unloaded.
-
void unload_policy(std::size_t index)
Unload a vendor change policy at the specified index.
- Parameters:
index – The index of the policy to unload (0-based).
- Throws:
VendorChangeManagerError – if index is out of bounds.
-
std::size_t unload_policies_matching_source(const std::string &source_pattern)
Unload vendor change policies whose source matches the specified pattern. The pattern may contain glob wildcards.
- Parameters:
source_pattern – A glob pattern to match against policy sources.
- Throws:
VendorChangeManagerError – if the pattern is invalid.
- Returns:
The number of policies that were unloaded.
-
std::size_t get_loaded_policies_count() const noexcept
Get the number of loaded vendor change policies.
- Returns:
The number of currently loaded policies.
-
const std::string &get_loaded_policy_source(std::size_t index) const
Get the source (origin) of a loaded vendor change policy.
- Parameters:
index – The index of the loaded policy (0-based).
- Throws:
VendorChangeManagerError – if index is out of bounds.
- Returns:
The source string (file URI or custom label with
text:prefix).
-
std::string get_loaded_policy_as_toml(std::size_t index) const
Get a loaded vendor change policy as a TOML string.
- Parameters:
index – The index of the loaded policy (0-based).
- Throws:
VendorChangeManagerError – if index is out of bounds.
- Returns:
The policy formatted as a TOML string.
-
std::string get_loaded_policy_as_compact(std::size_t index) const
Get a loaded vendor change policy as a compact format string.
- Parameters:
index – The index of the loaded policy (0-based).
- Throws:
VendorChangeManagerError – if index is out of bounds.
- Returns:
The policy formatted as a compact string.
-
std::filesystem::path save_policy_from_toml(std::string_view toml_content, std::string_view source, const std::filesystem::path &base_filename, bool allow_replace)
Save a vendor change policy from TOML format to a configuration file in the vendor directory (
/etc/dnf/vendors.d/or installroot equivalent). The TOML content is validated by parsing before saving.- Parameters:
toml_content – The policy in TOML format.
source – Origin of the policy (for error messages and validation).
base_filename – Base filename without extension or path (e.g.,
"my-policy"). Must not contain path components. The.confextension is added automatically.allow_replace – If
true, allows overwriting an existing policy file. Iffalse, throws if the file already exists.
- Throws:
VendorChangeManagerError – if validation or file write fails, if base_filename contains path components, or if file exists and allow_replace is false.
- Returns:
Path to the created policy file.
-
std::filesystem::path save_policy_from_toml(const std::filesystem::path &path, const std::filesystem::path &base_filename, bool allow_replace)
Save a vendor change policy from a TOML file to a configuration file in the vendor directory (
/etc/dnf/vendors.d/or installroot equivalent). The TOML file content is validated by parsing before saving.- Parameters:
path – Path to the TOML file containing the policy.
base_filename – Base filename without extension or path (e.g.,
"my-policy"). Must not contain path components. The.confextension is added automatically.allow_replace – If
true, allows overwriting an existing policy file. Iffalse, throws if the file already exists.
- Throws:
VendorChangeManagerError – if file read, validation, or write fails, if base_filename contains path components, or if file exists and allow_replace is false.
- Returns:
Path to the created policy file.
-
std::filesystem::path save_policy_from_compact(std::string_view policy_str, std::string_view source, const std::filesystem::path &base_filename, bool allow_replace)
Save a vendor change policy from compact format to a configuration file in the vendor directory (
/etc/dnf/vendors.d/or installroot equivalent). The policy is converted from compact format to TOML before saving.- Parameters:
policy_str – The policy in compact format.
source – Origin of the policy (for error messages).
base_filename – Base filename without extension or path (e.g.,
"my-policy"). Must not contain path components. The.confextension is added automatically.allow_replace – If
true, allows overwriting an existing policy file. Iffalse, throws if the file already exists.
- Throws:
VendorChangeManagerError – if conversion or file write fails, if base_filename contains path components, or if file exists and allow_replace is false.
- Returns:
Path to the created policy file.
-
std::filesystem::path remove_policy_file(const std::filesystem::path &base_filename)
Remove a vendor change policy configuration file. Removes the file from the vendor configuration directory (
/etc/dnf/vendors.d/or installroot equivalent).- Parameters:
base_filename – Base filename without extension or path (e.g.,
"my-policy"). Must not contain path components. The.confextension is added automatically.- Throws:
VendorChangeManagerError – if base_filename contains path components or file removal fails.
- Returns:
Path to the removed policy file.
-
std::vector<std::filesystem::path> get_policy_files() const
Get a list of all vendor change policy configuration files. Returns paths to all
.conffiles from both vendor configuration directories (/etc/dnf/vendors.d/and/usr/share/dnf5/vendors.d/or their installroot equivalents). The list is sorted in the same order as policies are loaded.- Returns:
Vector of paths to policy configuration files.
-
bool is_policy_file_manageable(const std::filesystem::path &path) const
Check if a policy file is manageable (can be removed or modified). Returns
trueif the file is in the writable vendor configuration directory (/etc/dnf/vendors.d/or installroot equivalent). Files in the distribution directory (/usr/share/dnf5/vendors.d/) are system-provided and not manageable.- Parameters:
path – Path to a policy file.
- Returns:
trueif the file can be managed (removed/modified),falseotherwise.
-
std::filesystem::path get_masked_policy_file(const std::filesystem::path &path) const
Get the path to the policy file that is masked by the given file. A file in the vendor configuration directory (
/etc/dnf/vendors.d/) masks a file with the same name in the distribution directory (/usr/share/dnf5/vendors.d/).- Parameters:
path – Path to a policy file in the vendor configuration directory.
- Returns:
Path to the masked file if the masked file exists, empty path otherwise (if the masked file does not exist or path is invalid).
-
std::filesystem::path find_policy_file(const std::filesystem::path &base_filename) const
Find an existing policy file by base filename. Searches for a policy file with the given base filename, preferring the vendor configuration directory (
/etc/dnf/vendors.d/) over the distribution directory (/usr/share/dnf5/vendors.d/).- Parameters:
base_filename – Base filename without extension or path (e.g.,
"my-policy").- Returns:
Path to the existing policy file (vendor or distribution), empty path if no such file exists.
Public Static Functions
-
static std::string convert_policy_toml_to_compact(std::string_view toml_content, std::string_view source)
Convert a vendor change policy from TOML content to compact format.
- Parameters:
toml_content – The TOML content to parse.
source – Origin of the policy (for error messages).
- Throws:
VendorChangeManagerError – if parsing fails.
- Returns:
The policy formatted as a compact string.
-
static std::string convert_policy_toml_to_compact(const std::filesystem::path &path)
Convert a vendor change policy from TOML file to compact format.
- Parameters:
path – Path to the TOML configuration file.
- Throws:
VendorChangeManagerError – if parsing fails.
- Returns:
The policy formatted as a compact string.
-
static std::string convert_policy_compact_to_toml(std::string_view compact_str, std::string_view source)
Convert a vendor change policy from compact format to TOML format.
- Parameters:
compact_str – The policy in compact format.
source – Origin of the policy (for error messages).
- Throws:
VendorChangeManagerError – if parsing fails.
- Returns:
The policy formatted as a TOML string.
-
static std::filesystem::path extract_policy_base_filename(const std::filesystem::path &path)
Extract base filename from a policy file path. Returns the filename without directory path and without the
.confextension. This is useful for converting paths returned by :func:get_policy_files()to the format expected by :func:remove_policy_file()and :func:save_policy_from_compact().- Parameters:
path – Path to a policy file (e.g.,
"/etc/dnf/vendors.d/my-policy.conf"). Must have.confextension.- Throws:
VendorChangeManagerError – if path does not have
.confextension.- Returns:
Base filename without extension (e.g.,
"my-policy").
Friends
- friend class libdnf5::Base
-
~VendorChangeManager()
-
class VendorChangeManagerError : public libdnf5::Error
- #include <vendor_change_manager_errors.hpp>
Error related to VendorChangeManager.
Public Functions
-
inline virtual const char *get_domain_name() const noexcept override
- Returns:
Error class’ domain name”
-
template<AllowedErrorArgTypes... Args>
inline explicit Error(BgettextMessage format, Args... args) A constructor that supports formatting the error message.
- Parameters:
format – The format string for the message.
args – The format arguments.
-
template<AllNamedErrorArgs... RestArgs>
inline explicit Error(BgettextMessage format, NamedErrorArg first_arg, RestArgs... rest_args) A constructor that supports formatting the error message with NamedErrorArg arguments. Requires AT LEAST ONE named argument (FirstArg) to avoid ambiguity with the zero-argument original constructor.
- Parameters:
format – The format string for the message.
first_arg – The first named format argument.
rest_args – Additional named format arguments.
-
inline virtual const char *get_domain_name() const noexcept override