dnf_repofile/mainconfig.rs
1//! The DNF `[main]` configuration section.
2//!
3//! This module defines [`MainConfig`], a strongly-typed representation of the
4//! DNF `[main]` section from `/etc/dnf/dnf.conf`. It contains 57 fields
5//! covering:
6//!
7//! - **Paths** — `cachedir`, `logdir`, `installroot`, `reposdir`, `varsdir`, etc.
8//! - **Booleans** — `keepcache`, `best`, `strict`, `plugins`, `obsoletes`, etc.
9//! - **Numerics** — `debuglevel`, `log_rotate`, `installonly_limit`, `errorlevel`, etc.
10//! - **Enums** — `multilib_policy`, `persistence`, `rpmverbosity`
11//! - **Raw data** — `extras` for keys not known to the library
12//!
13//! Use [`MainConfig::default()`] to create an empty config, or parse one via
14//! [`RepoFile::parse`](crate::RepoFile::parse).
15
16use crate::types::*;
17use camino::Utf8PathBuf;
18use indexmap::IndexMap;
19
20/// DNF `[main]` configuration section.
21///
22/// Represents all 57 known DNF main configuration options as strongly-typed
23/// optional fields. Unknown keys are stashed in [`extras`](MainConfig::extras)
24/// for round-trip fidelity.
25///
26/// # Examples
27///
28/// ```
29/// use dnf_repofile::MainConfig;
30///
31/// // Start with defaults (all fields None)
32/// let mut config = MainConfig::default();
33///
34/// // Set some values
35/// config.keepcache = Some(dnf_repofile::DnfBool::True);
36/// config.debuglevel = dnf_repofile::DebugLevel::try_new(5).ok();
37/// ```
38///
39/// Parse from a `.repo` file string via [`RepoFile`](crate::RepoFile):
40///
41/// ```
42/// use dnf_repofile::RepoFile;
43///
44/// let input = "[main]\ncachedir=/var/cache/dnf\nkeepcache=0\ndebuglevel=2\n";
45/// let rf = RepoFile::parse(input).unwrap();
46/// let main = rf.main().unwrap();
47/// assert_eq!(
48/// main.data.cachedir.as_ref().map(|p| p.as_str()),
49/// Some("/var/cache/dnf")
50/// );
51/// ```
52#[derive(Debug, Clone, PartialEq, Eq, Default)]
53pub struct MainConfig {
54 /// System architecture (e.g., `"x86_64"`, `"aarch64"`).
55 pub arch: Option<String>,
56 /// Base hardware architecture.
57 pub basearch: Option<String>,
58 /// OS release version identifier.
59 pub releasever: Option<String>,
60 /// Directory for the DNF cache.
61 pub cachedir: Option<Utf8PathBuf>,
62 /// Directory for persistent data.
63 pub persistdir: Option<Utf8PathBuf>,
64 /// Directory for log files.
65 pub logdir: Option<Utf8PathBuf>,
66 /// Path to the DNF configuration file.
67 pub config_file_path: Option<Utf8PathBuf>,
68 /// Root directory for package installation.
69 pub installroot: Option<Utf8PathBuf>,
70 /// Directories containing `.repo` files.
71 pub reposdir: Vec<Utf8PathBuf>,
72 /// Directories containing variable definition files.
73 pub varsdir: Vec<Utf8PathBuf>,
74 /// Directories for plugin configuration files.
75 pub pluginconfpath: Vec<Utf8PathBuf>,
76 /// Directories containing DNF plugins.
77 pub pluginpath: Vec<Utf8PathBuf>,
78 /// Debug message verbosity level (0–10, default 2).
79 pub debuglevel: Option<DebugLevel>,
80 /// Log file verbosity level (0–10, default 9).
81 pub logfilelevel: Option<LogLevel>,
82 /// Number of log files to keep before rotation (default 4).
83 pub log_rotate: Option<LogRotate>,
84 /// Maximum log file size in bytes.
85 pub log_size: Option<StorageSize>,
86 /// Maximum number of kernel packages to keep (default 3).
87 pub installonly_limit: Option<InstallOnlyLimit>,
88 /// Error message verbosity level (0–10, default 3).
89 pub errorlevel: Option<ErrorLevel>,
90 /// Time in seconds between metadata timer syncs (default 10800).
91 pub metadata_timer_sync: Option<MetadataTimerSync>,
92 /// Allow `obsoletes` to replace packages from different vendors.
93 pub allow_vendor_change: Option<DnfBool>,
94 /// Automatically answer "no" to all questions.
95 pub assumeno: Option<DnfBool>,
96 /// Automatically answer "yes" to all questions.
97 pub assumeyes: Option<DnfBool>,
98 /// Check whether the running kernel is the latest installed.
99 pub autocheck_running_kernel: Option<DnfBool>,
100 /// Upgrade to the highest available package version.
101 pub best: Option<DnfBool>,
102 /// Run entirely from cache (no network).
103 pub cacheonly: Option<DnfBool>,
104 /// Check the age of the configuration file.
105 pub check_config_file_age: Option<DnfBool>,
106 /// Remove dependencies that are no longer needed.
107 pub clean_requirements_on_remove: Option<DnfBool>,
108 /// Enable debug output from the dependency solver.
109 pub debug_solver: Option<DnfBool>,
110 /// Default answer "yes" to all questions.
111 pub defaultyes: Option<DnfBool>,
112 /// Check available disk space before operations.
113 pub diskspacecheck: Option<DnfBool>,
114 /// Exclude packages from weak dependency autodetection.
115 pub exclude_from_weak_autodetect: Option<DnfBool>,
116 /// Exit immediately if a lock cannot be acquired.
117 pub exit_on_lock: Option<DnfBool>,
118 /// Verify GPG keys via DNS.
119 pub gpgkey_dns_verification: Option<DnfBool>,
120 /// Ignore architecture mismatches.
121 pub ignorearch: Option<DnfBool>,
122 /// Install weak dependencies automatically.
123 pub install_weak_deps: Option<DnfBool>,
124 /// Keep downloaded package files after installation.
125 pub keepcache: Option<DnfBool>,
126 /// Compress rotated log files.
127 pub log_compress: Option<DnfBool>,
128 /// Handle module obsoletes.
129 pub module_obsoletes: Option<DnfBool>,
130 /// Allow module stream switching.
131 pub module_stream_switch: Option<DnfBool>,
132 /// Handle package obsoletes.
133 pub obsoletes: Option<DnfBool>,
134 /// Enable DNF plugins.
135 pub plugins: Option<DnfBool>,
136 /// Protect the running kernel from removal.
137 pub protect_running_kernel: Option<DnfBool>,
138 /// Fail on any error during dependency resolution.
139 pub strict: Option<DnfBool>,
140 /// Upgrade group objects as a unit.
141 pub upgrade_group_objects_upgrade: Option<DnfBool>,
142 /// Enable zchunk metadata compression.
143 pub zchunk: Option<DnfBool>,
144 /// Packages that should only ever be installed, never upgraded.
145 pub installonlypkgs: Vec<String>,
146 /// Packages protected from automatic removal.
147 pub protected_packages: Vec<String>,
148 /// Packages excluded from weak dependency detection.
149 pub exclude_from_weak: Vec<String>,
150 /// Types of group packages to install.
151 pub group_package_types: Vec<String>,
152 /// Optional repository metadata types to download.
153 pub optional_metadata_types: Vec<String>,
154 /// RPM transaction flags (scripts, triggers, docs, etc.).
155 pub tsflags: Vec<TsFlag>,
156 /// Paths protected from `/usr` drift.
157 pub usr_drift_protected_paths: Vec<String>,
158 /// Multilib package installation policy.
159 pub multilib_policy: Option<MultilibPolicy>,
160 /// SQLite persistence mode for repository metadata.
161 pub persistence: Option<Persistence>,
162 /// RPM transaction verbosity level.
163 pub rpmverbosity: Option<RpmVerbosity>,
164 /// Module platform identifier for modularity.
165 pub module_platform_id: Option<ModulePlatformId>,
166 /// Unrecognized key-value pairs preserved for round-trip fidelity.
167 pub extras: IndexMap<String, Vec<String>>,
168}