Skip to content

Commit 4af36ba

Browse files
committed
fix: respect update_before_build=False during builddep (issue#1420)
dnf5 builddep upgrades already-installed packages even when update_before_build is disabled. Work around this by excluding all installed package names from repo lookups during dependency installation, so only genuinely missing packages are pulled in. Fixes: #1420 Assisted-By: Claude Opus 4.6 <noreply@anthropic.com>
1 parent 5182969 commit 4af36ba

2 files changed

Lines changed: 27 additions & 2 deletions

File tree

mock/py/mockbuild/backend.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -193,18 +193,38 @@ def prepareSpec(self, srpm=None, spec=None):
193193

194194
return spec_path
195195

196+
def _get_update_exclude_opts(self):
197+
"""
198+
When update_before_build is disabled, return --exclude options for all
199+
installed packages so that builddep/install won't upgrade them.
200+
Works around https://github.com/rpm-software-management/dnf5/issues/1747
201+
"""
202+
if self.config.get('update_before_build', True):
203+
return []
204+
205+
command = [self.config['rpm_command'], "-qa", "--queryformat", "%{NAME}\\n",
206+
"--root", self.buildroot.make_chroot_path()]
207+
out, _ = self.buildroot.doOutChroot(command, returnOutput=True,
208+
printOutput=False, shell=False)
209+
pkg_names = set(filter(None, out.strip().splitlines()))
210+
if not pkg_names:
211+
return []
212+
return ['--exclude=' + ','.join(sorted(pkg_names))]
213+
196214
@traceLog()
197215
def installSrpmDeps(self, *srpms):
198216
"""Figure out deps from srpm. Call package manager to install them"""
199217
try:
200218
self.uid_manager.becomeUser(0, 0)
201219

220+
exclude_opts = self._get_update_exclude_opts()
221+
202222
deps = self.getPreconfiguredDeps(srpms)
203223
if deps:
204-
self.buildroot.pkg_manager.install(*deps, check=True)
224+
self.buildroot.pkg_manager.install(*exclude_opts, *deps, check=True)
205225

206226
# install actual build dependencies
207-
self.buildroot.pkg_manager.builddep(*srpms, check=True)
227+
self.buildroot.pkg_manager.builddep(*exclude_opts, *srpms, check=True)
208228
finally:
209229
self.uid_manager.restorePrivs()
210230

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
The `config_opts['update_before_build'] = False` option is now respected
2+
during build dependency installation. Previously, `dnf5 builddep` would
3+
upgrade already-installed packages even when this option was disabled,
4+
as reported in [issue#1420][]. Mock now excludes installed packages from
5+
repository lookups during `builddep`/`install`, preventing unwanted upgrades.

0 commit comments

Comments
 (0)