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), rb.create_runtime(joinpaths(installroot,runtime),
compression=compression, compressargs=compressargs, compression=compression, compressargs=compressargs,
size=size) size=size)
rb.finished()
logger.info("preparing to build output tree and boot images") logger.info("preparing to build output tree and boot images")
treebuilder = TreeBuilder(product=self.product, arch=self.arch, treebuilder = TreeBuilder(product=self.product, arch=self.arch,

View File

@ -169,8 +169,14 @@ class LoraxTemplateRunner(object):
return joinpaths(self.inroot, path) return joinpaths(self.inroot, path)
def _filelist(self, *pkgs): def _filelist(self, *pkgs):
pkglist = self.dbo.doPackageLists(pkgnarrow="installed", patterns=pkgs) """ Return the list of files in the packages """
return set([f for pkg in pkglist for f in pkg.files]) 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): def _getsize(self, *files):
return sum(os.path.getsize(self._out(f)) for f in files if os.path.isfile(self._out(f))) 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) logger.error("The transaction process has ended abruptly: %s", e)
queue.put(('quit', str(e))) queue.put(('quit', str(e)))
self.dbo.reset()
try: try:
logger.info("Checking dependencies") logger.info("Checking dependencies")
self.dbo.resolve() self.dbo.resolve()
@ -551,13 +556,22 @@ class LoraxTemplateRunner(object):
logger.info("Performing post-installation setup tasks") logger.info("Performing post-installation setup tasks")
process.join() process.join()
# verify if all packages that were supposed to be installed, # close down the base and re-init it to pick up changes
# 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)
self.dbo.close() 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): def removefrom(self, pkg, *globs):
''' '''

View File

@ -84,6 +84,7 @@ class RuntimeBuilder(object):
self.add_template_vars = add_template_vars or {} self.add_template_vars = add_template_vars or {}
self._installpkgs = installpkgs or [] self._installpkgs = installpkgs or []
self._runner.defaults = self.vars self._runner.defaults = self.vars
self.dbo.reset()
def _install_branding(self): def _install_branding(self):
release = None release = None
@ -173,6 +174,13 @@ class RuntimeBuilder(object):
imgutils.mksquashfs(workdir, outfile, compression, compressargs) imgutils.mksquashfs(workdir, outfile, compression, compressargs)
remove(workdir) remove(workdir)
def finished(self):
""" Done using RuntimeBuilder
Close the dnf base object
"""
self.dbo.close()
class TreeBuilder(object): class TreeBuilder(object):
'''Builds the arch-specific boot images. '''Builds the arch-specific boot images.
inroot should be the installtree root (the newly-built runtime dir)''' 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 conf.cachedir = cachedir
# Turn off logging to the console # Turn off logging to the console
conf.debuglevel = 0 conf.debuglevel = 10
conf.errorlevel = 0 conf.errorlevel = 0
dnfbase.logging.setup_from_dnf_conf(conf) dnfbase.logging.setup_from_dnf_conf(conf)