dnf: remove files from installed packages

This is a workaround for a current dnf bug, it doesn't update the state
of the packages after they are installed so we tear down the base dnf
object and create a new one pointing to the installroot.

There is an additional issue with the list of files returned, hawkey and
dnf don't appear to make a distinction between files, dirs and ghosted
dirs like yum did, this can result in too much being removed (eg. all of
/etc/selinux/) so we only remove files not directories.
This commit is contained in:
Brian C. Lane 2014-06-19 14:43:56 -07:00
parent 431ca6cea4
commit 345cc89ee0
4 changed files with 33 additions and 10 deletions

View File

@ -302,6 +302,7 @@ class Lorax(BaseLoraxClass):
rb.create_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs,
size=size)
rb.finished()
logger.info("preparing to build output tree and boot images")
treebuilder = TreeBuilder(product=self.product, arch=self.arch,

View File

@ -169,8 +169,14 @@ class LoraxTemplateRunner(object):
return joinpaths(self.inroot, path)
def _filelist(self, *pkgs):
pkglist = self.dbo.doPackageLists(pkgnarrow="installed", patterns=pkgs)
return set([f for pkg in pkglist for f in pkg.files])
""" Return the list of files in the packages """
pkglist = []
for pkg_glob in pkgs:
pkglist += list(self.dbo.sack.query().installed().filter(name__glob=pkg_glob))
# dnf/hawkey doesn't make any distinction between file, dir or ghost like yum did
# so only return the files.
return set(f for pkg in pkglist for f in pkg.files if not os.path.isdir(self._out(f)))
def _getsize(self, *files):
return sum(os.path.getsize(self._out(f)) for f in files if os.path.isfile(self._out(f)))
@ -513,7 +519,6 @@ class LoraxTemplateRunner(object):
logger.error("The transaction process has ended abruptly: %s", e)
queue.put(('quit', str(e)))
self.dbo.reset()
try:
logger.info("Checking dependencies")
self.dbo.resolve()
@ -551,13 +556,22 @@ class LoraxTemplateRunner(object):
logger.info("Performing post-installation setup tasks")
process.join()
# verify if all packages that were supposed to be installed,
# are really installed
errs = [t.po for t in self.dbo.tsInfo if not self.dbo.rpmdb.contains(po=t.po)]
for po in errs:
logger.error("package '%s' was not installed", po)
# close down the base and re-init it to pick up changes
self.dbo.close()
del self.dbo
self.dbo = dnf.Base()
conf = self.dbo.conf
# Point inside the installroot
conf.installroot = self.outroot
conf.prepend_installroot('persistdir')
conf.debuglevel = 10
conf.errorlevel = 0
RELEASEVER = dnf.rpm.detect_releasever(self.dbo.conf.installroot)
self.dbo.conf.substitutions['releasever'] = RELEASEVER
self.dbo.read_all_repos()
self.dbo.fill_sack(load_system_repo=False)
self.dbo.read_comps()
def removefrom(self, pkg, *globs):
'''

View File

@ -84,6 +84,7 @@ class RuntimeBuilder(object):
self.add_template_vars = add_template_vars or {}
self._installpkgs = installpkgs or []
self._runner.defaults = self.vars
self.dbo.reset()
def _install_branding(self):
release = None
@ -173,6 +174,13 @@ class RuntimeBuilder(object):
imgutils.mksquashfs(workdir, outfile, compression, compressargs)
remove(workdir)
def finished(self):
""" Done using RuntimeBuilder
Close the dnf base object
"""
self.dbo.close()
class TreeBuilder(object):
'''Builds the arch-specific boot images.
inroot should be the installtree root (the newly-built runtime dir)'''

View File

@ -250,7 +250,7 @@ def get_dnf_base_object(installroot, repositories, mirrorlists=None,
conf.cachedir = cachedir
# Turn off logging to the console
conf.debuglevel = 0
conf.debuglevel = 10
conf.errorlevel = 0
dnfbase.logging.setup_from_dnf_conf(conf)