[elbe-devel] [PATCH] cdroms: remove and retry if add package fails

John Ogness john.ogness at linutronix.de
Tue Sep 20 14:16:20 CEST 2016


If the package installed in chroot has the same version number but
differs from the package in srcrepo or binrepo, elbe aborts with
an error when the iso images should be generated. Rather than
abort with an error, remove the package from the repo, then try
to add again. If it fails a second time, abort.

This situation can arise if a new pbuilder package is created but
the version number was not incremented.

Signed-off-by: John Ogness <john.ogness at linutronix.de>

diff --git a/elbepack/cdroms.py b/elbepack/cdroms.py
index b7bcea2..aebb80b 100644
--- a/elbepack/cdroms.py
+++ b/elbepack/cdroms.py
@@ -27,6 +27,7 @@ from elbepack.aptpkgutils import XMLPackage
 from elbepack.aptprogress import ElbeAcquireProgress
 from elbepack.filesystem  import Filesystem, hostfs
 from elbepack.dump        import get_initvm_pkglist
+from elbepack.shellhelper import CommandError
 from apt import Cache
 
 CDROM_SIZE = 640*1000*1000
@@ -46,13 +47,22 @@ def mk_source_cdrom(rfs, arch, codename, init_codename, target, log, cdrom_size=
     pkglist = cache.get_installed_pkgs()
 
     for pkg in pkglist:
-        try:
-            dsc = cache.download_source( pkg.name, '/var/cache/elbe/sources' )
-            repo.includedsc( dsc )
-        except ValueError as ve:
-            log.printo( "No sources for Package " + pkg.name + "-" + pkg.installed_version )
-        except FetchError as fe:
-            log.printo( "Source for Package " + pkg.name + "-" + pkg.installed_version + " could not be downloaded" )
+        retried = False
+        while True:
+            try:
+                dsc = cache.download_source( pkg.name, '/var/cache/elbe/sources' )
+                repo.includedsc( dsc )
+            except ValueError as ve:
+                log.printo( "No sources for Package " + pkg.name + "-" + pkg.installed_version )
+            except FetchError as fe:
+                log.printo( "Source for Package " + pkg.name + "-" + pkg.installed_version + " could not be downloaded" )
+            except CommandError as ce:
+                if retried:
+                    raise ce
+                repo.removesrc(dsc)
+                retried = True
+                continue
+            break
 
     repo.finalize ()
 
@@ -140,19 +150,28 @@ def mk_binary_cdrom(rfs, arch, codename, init_codename, xml, target, log, cdrom_
     cache = get_rpcaptcache( rfs, "aptcache.log", arch )
     pkglist = cache.get_installed_pkgs ()
     for pkg in pkglist:
-        try:
-            deb = cache.download_binary( pkg.name,
-                                        '/var/cache/elbe/binaries/added',
-                                        pkg.installed_version )
-            target_repo.includedeb(deb, 'added')
-        except KeyError as ke:
-            log.printo( str (ke) )
-        except ValueError as ve:
-            log.printo( "No Package " + pkg.name + "-" + pkg.installed_version )
-        except FetchError as fe:
-            log.printo( "Package " + pkg.name + "-" + str (pkg.installed_version) + " could not be downloaded" )
-        except TypeError as te:
-            log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " missing name or version" )
+        retried = False
+        while True:
+            try:
+                deb = cache.download_binary( pkg.name,
+                                            '/var/cache/elbe/binaries/added',
+                                            pkg.installed_version )
+                target_repo.includedeb(deb, 'added')
+            except KeyError as ke:
+                log.printo( str (ke) )
+            except ValueError as ve:
+                log.printo( "No Package " + pkg.name + "-" + pkg.installed_version )
+            except FetchError as fe:
+                log.printo( "Package " + pkg.name + "-" + str (pkg.installed_version) + " could not be downloaded" )
+            except TypeError as te:
+                log.printo( "Package " + pkg.name + "-" + pkg.installed_version + " missing name or version" )
+            except CommandError as ce:
+                if retried:
+                    raise ce
+                target_repo.removedeb(pkg.name, 'added')
+                retried = True
+                continue
+            break
 
     repo.finalize()
     target_repo.finalize ()
diff --git a/elbepack/repomanager.py b/elbepack/repomanager.py
index af4475a..2e93168 100644
--- a/elbepack/repomanager.py
+++ b/elbepack/repomanager.py
@@ -168,13 +168,27 @@ class RepoBase(object):
     def _include( self, path, codename, component):
         self.log.do( 'reprepro --ignore=wrongdistribution --keepunreferencedfiles --export=never --basedir "' + self.fs.path  + '" -C ' + component + ' -P normal -S misc include ' + codename + ' ' + path )
 
+    def _removedeb(self, pkgname, codename, component):
+        self.log.do( "reprepro --basedir %s remove %s %s" % (self.fs.path, codename, pkgname))
+
+    def removedeb(self, pkgname, component="main"):
+        self._removedeb (pkgname, self.repo_attr.codename, component)
+
+    def _removesrc(self, srcname, codename, component):
+        self.log.do( "reprepro --basedir %s removesrc %s %s" % (self.fs.path, codename, srcname))
+
+    def removesrc(self, path, component="main"):
+        for p in Deb822.iter_paragraphs(file(path)):
+            if 'Source' in p:
+                self._removesrc(p['Source'], self.repo_attr.codename, component)
+
     def _remove( self, path, codename, component):
         os.environ ['GNUPGHOME'] = "/var/cache/elbe/gnupg"
         for p in Deb822.iter_paragraphs(file(path)):
             if 'Source' in p:
-                self.log.do( "reprepro --basedir %s removesrc %s %s" % (self.fs.path, codename, p['Source']))
+                self._removesrc(p['Source'], codename, component)
             elif 'Package' in p:
-                self.log.do( "reprepro --basedir %s remove %s %s" % (self.fs.path, codename, p['Package']))
+                self._removedeb(p['Package'], codename, component)
 
     def _includedsc( self, path, codename, component):
         if self.maxsize:
-- 
2.8.1




More information about the elbe-devel mailing list