From 345cc89ee00730f291462a15e6e613b17f18ef46 Mon Sep 17 00:00:00 2001 From: "Brian C. Lane" Date: Thu, 19 Jun 2014 14:43:56 -0700 Subject: [PATCH] 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. --- src/pylorax/__init__.py | 1 + src/pylorax/ltmpl.py | 32 +++++++++++++++++++++++--------- src/pylorax/treebuilder.py | 8 ++++++++ src/sbin/lorax | 2 +- 4 files changed, 33 insertions(+), 10 deletions(-) diff --git a/src/pylorax/__init__.py b/src/pylorax/__init__.py index 44b180bc..8a46c069 100644 --- a/src/pylorax/__init__.py +++ b/src/pylorax/__init__.py @@ -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, diff --git a/src/pylorax/ltmpl.py b/src/pylorax/ltmpl.py index f5d6f335..5e8c2679 100644 --- a/src/pylorax/ltmpl.py +++ b/src/pylorax/ltmpl.py @@ -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): ''' diff --git a/src/pylorax/treebuilder.py b/src/pylorax/treebuilder.py index 5a56233d..5fac1350 100644 --- a/src/pylorax/treebuilder.py +++ b/src/pylorax/treebuilder.py @@ -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)''' diff --git a/src/sbin/lorax b/src/sbin/lorax index cfa66d1a..7d96d43f 100755 --- a/src/sbin/lorax +++ b/src/sbin/lorax @@ -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)