[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Bug#924308: unblock: python-apt/1.8.4



Package: release.debian.org
Severity: normal
User: release.debian.org@packages.debian.org
Usertags: unblock

Please unblock package python-apt

This upload fixes a few locking issues, most noticeably, Bug #922416. 

After fixing the archive locking mentioned in that bug, I also fixed the
lists/ locking in the update() function which could accidentally be unreleased
if slist.read_main_list() raises an exception. (second point in changelog).

These fixes use context managers, hence everything is indented a level
more, I therefore also provided a debdiff generated with -w, filename ending
in .w.diff.

I also updated the mirror lists shipped in the package as part of the
usual pre-build script.

unblock python-apt/1.8.4

-- 
debian developer - deb.li/jak | jak-linux.org - free software dev
ubuntu core developer                              i speak de, en
diff -Nru python-apt-1.8.3/apt/cache.py python-apt-1.8.4/apt/cache.py
--- python-apt-1.8.3/apt/cache.py	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/apt/cache.py	2019-03-11 12:49:18.000000000 +0100
@@ -70,6 +70,29 @@
     """Exception that is thrown when the cache is used after close()."""
 
 
+class _WrappedLock(object):
+    """Wraps an apt_pkg.FileLock to raise LockFailedException.
+
+    Initialized using a directory path."""
+
+    def __init__(self, path):
+        # type: (str) -> None
+        self._path = path
+        self._lock = apt_pkg.FileLock(os.path.join(path, "lock"))
+
+    def __enter__(self):
+        # type: () -> None
+        try:
+            return self._lock.__enter__()
+        except apt_pkg.Error as e:
+            raise LockFailedException(("Failed to lock directory %s: %s") %
+                                       (self._path, e))
+
+    def __exit__(self, typ, value, traceback):
+        # type: (object, object, object) -> None
+        return self._lock.__exit__(typ, value, traceback)
+
+
 class Cache(object):
     """Dictionary-like package cache.
 
@@ -135,6 +158,11 @@
             # Call InitSystem so the change to Dir::State::Status is actually
             # recognized (LP: #320665)
             apt_pkg.init_system()
+
+        # Prepare a lock object (context manager for archive lock)
+        archive_dir = apt_pkg.config.find_dir("Dir::Cache::Archives")
+        self._archive_lock = _WrappedLock(archive_dir)
+
         self.open(progress)
 
     def fix_broken(self):
@@ -426,16 +454,6 @@
         # fetched
         return self._run_fetcher(fetcher)
 
-    def _get_archive_lock(self, fetcher):
-        # type: (apt_pkg.Acquire) -> None
-        # get lock
-        archive_dir = apt_pkg.config.find_dir("Dir::Cache::Archives")
-        try:
-            fetcher.get_lock(archive_dir)
-        except apt_pkg.Error as e:
-            raise LockFailedException(("Failed to lock archive directory %s: "
-                                       " %s") % (archive_dir, e))
-
     def fetch_archives(self, progress=None, fetcher=None):
         # type: (AcquireProgress, apt_pkg.Acquire) -> int
         """Fetch the archives for all packages marked for install/upgrade.
@@ -457,10 +475,9 @@
         if fetcher is None:
             fetcher = apt_pkg.Acquire(progress)
 
-        self._get_archive_lock(fetcher)
-
-        return self._fetch_archives(fetcher,
-                                    apt_pkg.PackageManager(self._depcache))
+        with self._archive_lock:
+            return self._fetch_archives(fetcher,
+                                        apt_pkg.PackageManager(self._depcache))
 
     def is_virtual_package(self, pkgname):
         # type: (str) -> bool
@@ -520,43 +537,41 @@
         sources_list -- Update a alternative sources.list than the default.
         Note that the sources.list.d directory is ignored in this case
         """
-        lockfile = apt_pkg.config.find_dir("Dir::State::Lists") + "lock"
-        lock = apt_pkg.get_lock(lockfile)
-
-        if lock < 0:
-            raise LockFailedException("Failed to lock %s" % lockfile)
-
-        if sources_list:
-            old_sources_list = apt_pkg.config.find("Dir::Etc::sourcelist")
-            old_sources_list_d = apt_pkg.config.find("Dir::Etc::sourceparts")
-            old_cleanup = apt_pkg.config.find("APT::List-Cleanup")
-            apt_pkg.config.set("Dir::Etc::sourcelist",
-                               os.path.abspath(sources_list))
-            apt_pkg.config.set("Dir::Etc::sourceparts", "xxx")
-            apt_pkg.config.set("APT::List-Cleanup", "0")
-            slist = apt_pkg.SourceList()
-            slist.read_main_list()
-        else:
-            slist = self._list
+        with _WrappedLock(apt_pkg.config.find_dir("Dir::State::Lists")):
+            if sources_list:
+                old_sources_list = apt_pkg.config.find("Dir::Etc::sourcelist")
+                old_sources_list_d = (
+                    apt_pkg.config.find("Dir::Etc::sourceparts"))
+                old_cleanup = apt_pkg.config.find("APT::List-Cleanup")
+                apt_pkg.config.set("Dir::Etc::sourcelist",
+                                   os.path.abspath(sources_list))
+                apt_pkg.config.set("Dir::Etc::sourceparts", "xxx")
+                apt_pkg.config.set("APT::List-Cleanup", "0")
+                slist = apt_pkg.SourceList()
+                slist.read_main_list()
+            else:
+                slist = self._list
 
-        try:
-            if fetch_progress is None:
-                fetch_progress = apt.progress.base.AcquireProgress()
             try:
-                res = self._cache.update(fetch_progress, slist,
-                                         pulse_interval)
-            except SystemError as e:
-                raise FetchFailedException(e)
-            if not res and raise_on_error:
-                raise FetchFailedException()
-            else:
-                return res
-        finally:
-            os.close(lock)
-            if sources_list:
-                apt_pkg.config.set("Dir::Etc::sourcelist", old_sources_list)
-                apt_pkg.config.set("Dir::Etc::sourceparts", old_sources_list_d)
-                apt_pkg.config.set("APT::List-Cleanup", old_cleanup)
+                if fetch_progress is None:
+                    fetch_progress = apt.progress.base.AcquireProgress()
+                try:
+                    res = self._cache.update(fetch_progress, slist,
+                                             pulse_interval)
+                except SystemError as e:
+                    raise FetchFailedException(e)
+                if not res and raise_on_error:
+                    raise FetchFailedException()
+                else:
+                    return res
+            finally:
+                if sources_list:
+                    apt_pkg.config.set("Dir::Etc::sourcelist",
+                                       old_sources_list)
+                    apt_pkg.config.set("Dir::Etc::sourceparts",
+                                       old_sources_list_d)
+                    apt_pkg.config.set("APT::List-Cleanup",
+                                       old_cleanup)
 
     def install_archives(self, pm, install_progress):
         # type: (apt_pkg.PackageManager, InstallProgress) -> int
@@ -620,25 +635,25 @@
         with apt_pkg.SystemLock():
             pm = apt_pkg.PackageManager(self._depcache)
             fetcher = apt_pkg.Acquire(fetch_progress)
-            self._get_archive_lock(fetcher)
-
-            while True:
-                # fetch archives first
-                res = self._fetch_archives(fetcher, pm)
-
-                # then install
-                res = self.install_archives(pm, install_progress)
-                if res == pm.RESULT_COMPLETED:
-                    break
-                elif res == pm.RESULT_FAILED:
-                    raise SystemError("installArchives() failed")
-                elif res == pm.RESULT_INCOMPLETE:
-                    pass
-                else:
-                    raise SystemError("internal-error: unknown result code "
-                                      "from InstallArchives: %s" % res)
-                # reload the fetcher for media swaping
-                fetcher.shutdown()
+            with self._archive_lock:
+                while True:
+                    # fetch archives first
+                    res = self._fetch_archives(fetcher, pm)
+
+                    # then install
+                    res = self.install_archives(pm, install_progress)
+                    if res == pm.RESULT_COMPLETED:
+                        break
+                    elif res == pm.RESULT_FAILED:
+                        raise SystemError("installArchives() failed")
+                    elif res == pm.RESULT_INCOMPLETE:
+                        pass
+                    else:
+                        raise SystemError("internal-error: unknown result "
+                                          "code from InstallArchives: %s" %
+                                          res)
+                    # reload the fetcher for media swaping
+                    fetcher.shutdown()
         return (res == pm.RESULT_COMPLETED)
 
     def clear(self):
diff -Nru python-apt-1.8.3/data/templates/Debian.mirrors python-apt-1.8.4/data/templates/Debian.mirrors
--- python-apt-1.8.3/data/templates/Debian.mirrors	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/data/templates/Debian.mirrors	2019-03-11 12:49:18.000000000 +0100
@@ -219,7 +219,6 @@
 http://mirror.isoc.org.il/pub/debian/
 #LOC:IN
 http://debianmirror.nkn.in/debian/
-http://ftp.iitm.ac.in/debian/
 http://mirror.cse.iitk.ac.in/debian/
 #LOC:IR
 http://debian.asis.io/debian/
@@ -404,7 +403,6 @@
 http://ftp.utexas.edu/debian/
 http://mirror.cc.columbia.edu/debian/
 http://mirror.cogentco.com/debian/
-http://mirror.cs.uwm.edu/debian/
 http://mirror.hmc.edu/debian/
 http://mirror.keystealth.org/debian/
 http://mirror.math.princeton.edu/pub/debian/
diff -Nru python-apt-1.8.3/data/templates/Ubuntu.mirrors python-apt-1.8.4/data/templates/Ubuntu.mirrors
--- python-apt-1.8.3/data/templates/Ubuntu.mirrors	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/data/templates/Ubuntu.mirrors	2019-03-11 12:49:18.000000000 +0100
@@ -92,6 +92,7 @@
 http://mirrors.nju.edu.cn/ubuntu/
 http://mirrors.njupt.edu.cn/ubuntu/
 http://mirrors.nwafu.edu.cn/ubuntu/
+http://mirrors.shu.edu.cn/ubuntu/
 http://mirrors.sohu.com/ubuntu/
 http://mirrors.tuna.tsinghua.edu.cn/ubuntu/
 http://mirrors.ustc.edu.cn/ubuntu/
@@ -146,6 +147,7 @@
 http://packages.oth-regensburg.de/ubuntu/
 http://pubmirror01.lwlcom.net/ubuntu/
 http://suse.uni-leipzig.de/pub/releases.ubuntu.com/ubuntu/
+http://ubuntu.cybertips.info/ubuntu/
 http://ubuntu.mirror.lrz.de/ubuntu/
 http://ubuntu.mirror.tudos.de/ubuntu/
 http://ubuntu.unitedcolo.de/ubuntu/
@@ -166,6 +168,7 @@
 ftp://ftp.csuc.cat/ubuntu/archieve/
 http://dafi.inf.um.es/ubuntu/
 http://es-mirrors.evowise.com/ubuntu/
+http://es.mirror.burstable.org/ubuntu/
 http://ftp.caliu.cat/pub/distribucions/ubuntu/archive/
 http://ftp.udc.es/ubuntu/
 http://mirror.tedra.es/ubuntu/
@@ -179,6 +182,7 @@
 http://distrib-coffee.ipsl.jussieu.fr/pub/linux/ubuntu/
 http://fr.archive.ubuntu.com/ubuntu/
 http://ftp.rezopole.net/ubuntu/
+http://mir1.flosoft-servers.net/ubuntu/
 http://mirror.plusserver.com/ubuntu/ubuntu/
 http://mirror.ubuntu.ikoula.com/ubuntu/
 http://mirrors.ircam.fr/pub/ubuntu/archive/
@@ -190,12 +194,12 @@
 http://wwwftp.ciril.fr/pub/linux/ubuntu/archives/
 #LOC:GB
 http://archive.ubuntu.com/ubuntu/
-http://ftp.thunix.org/ubuntu/
 http://ftp.ticklers.org/archive.ubuntu.org/ubuntu/
 http://mirror.as29550.net/archive.ubuntu.com/
 http://mirror.bytemark.co.uk/ubuntu/
 http://mirror.freethought-internet.co.uk/ubuntu/
 http://mirror.mythic-beasts.com/ubuntu/
+http://mirror.ox.ac.uk/sites/archive.ubuntu.com/ubuntu/
 http://mirror.sax.uk.as61049.net/ubuntu/
 http://mirror.sov.uk.goscomb.net/ubuntu/
 http://mirror.vorboss.net/ubuntu-archive/
@@ -221,29 +225,31 @@
 #LOC:HR
 http://hr.archive.ubuntu.com/ubuntu/
 #LOC:HU
-http://ftp.freepark.org/ubuntu/
+http://ftp.fsn.hu/ubuntu/
+http://hu.archive.ubuntu.com/ubuntu/
+http://mirror.niif.hu/ubuntu/
 http://quantum-mirror.hu/mirrors/pub/ubuntu/
 #LOC:ID
 http://buaya.klas.or.id/ubuntu/
-http://kambing.ui.ac.id/ubuntu/
 http://kartolo.sby.datautama.net.id/ubuntu/
 http://kebo.pens.ac.id/ubuntu/
 http://mirror.biznetgio.com/ubuntu/
+http://mirror.deace.id/ubuntu/
 http://mirror.poliwangi.ac.id/ubuntu/
 http://mirror.unej.ac.id/ubuntu/
 http://repo.unpatti.ac.id/ubuntu/
+http://suro.ubaya.ac.id/ubuntu/
 #LOC:IE
 http://ftp.heanet.ie/pub/ubuntu/
 #LOC:IL
 http://mirror.isoc.org.il/pub/ubuntu/
 #LOC:IN
-http://ftp.iitm.ac.in/ubuntu/
 http://mirror.cse.iitk.ac.in/ubuntu/
 http://mirror.pramati.com/ubuntu/
 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu/
 http://repos.del.extreme-ix.org/ubuntu/
-http://ubuntu.mirror.snu.edu.in/ubuntu/
 #LOC:IR
+http://mirror.aminidc.com/ubuntu/
 http://mirror.armaghan.net/ubuntu/
 http://mirror.iranserver.com/ubuntu/
 http://mirror.rasanegar.com/ubuntu/archive/
@@ -335,9 +341,9 @@
 http://ubuntu.mirror.cambrium.nl/ubuntu/
 http://ubuntu.mirror.true.nl/ubuntu/
 #LOC:NO
-http://archive.mirror.blix.com/ubuntu/
 http://ftp.uninett.no/ubuntu/
 http://no.archive.ubuntu.com/ubuntu/
+http://no.mirrors.blix.com/ubuntu/
 http://ubuntu.uib.no/archive/
 #LOC:NP
 http://ubuntu.ntc.net.np/ubuntu/
@@ -350,6 +356,7 @@
 #LOC:PF
 http://pf.archive.ubuntu.com/ubuntu/
 #LOC:PH
+http://mirror.pregi.net/ubuntu/
 http://mirror.rise.ph/ubuntu/
 #LOC:PK
 http://mirrors.nayatel.com/ubuntu/
@@ -367,6 +374,7 @@
 http://archive.ubuntumirror.dei.uc.pt/ubuntu/
 http://ftp.rnl.tecnico.ulisboa.pt/pub/ubuntu/archive/
 http://glua.ua.pt/pub/ubuntu/
+http://mirrors.ptisp.pt/ubuntu/
 http://mirrors.up.pt/ubuntu/
 #LOC:RO
 http://ftp.gts.lug.ro/ubuntu/
@@ -387,6 +395,8 @@
 http://mirror.truenetwork.ru/ubuntu/
 http://mirror.yandex.ru/ubuntu/
 http://mirrors.powernet.com.ru/ubuntu/
+#LOC:SA
+http://ubuntu.mirrors.isu.net.sa/ubuntu/
 #LOC:SE
 http://ftp.acc.umu.se/ubuntu/
 http://ftp.lysator.liu.se/ubuntu/
@@ -401,6 +411,7 @@
 #LOC:SI
 http://ftp.arnes.si/pub/mirrors/ubuntu/
 #LOC:SK
+http://ftp.energotel.sk/pub/linux/ubuntu/
 http://mirror.vnet.sk/ubuntu/
 http://tux.rainside.sk/ubuntu/
 #LOC:TH
@@ -413,6 +424,7 @@
 #LOC:TN
 http://ubuntu.mirror.tn/ubuntu/
 #LOC:TR
+http://ftp.linux.org.tr/ubuntu/
 http://mirror.idealhosting.net.tr/ubuntu/
 http://mirror.muvhost.com/ubuntu/
 http://mirror.ni.net.tr/ubuntu/
@@ -420,7 +432,6 @@
 http://ubuntu.turhost.com/ubuntu/
 http://ubuntu.vargonen.com/ubuntu/
 #LOC:TW
-http://debian.linux.org.tw/ubuntu/
 http://free.nchc.org.tw/ubuntu/
 http://ftp.ntou.edu.tw/ubuntu/
 http://ftp.tku.edu.tw/ubuntu/
@@ -431,13 +442,13 @@
 http://ubuntu.cs.nctu.edu.tw/ubuntu/
 http://ubuntu.stu.edu.tw/ubuntu/
 #LOC:TZ
-http://deb-mirror.habari.co.tz/ubuntu/
 http://mirror.aptus.co.tz/pub/ubuntuarchive/
 #LOC:UA
 http://mirror.mirohost.net/ubuntu/
 http://ubuntu.colocall.net/ubuntu/
 http://ubuntu.ip-connect.vn.ua/
 http://ubuntu.mirrors.omnilance.com/ubuntu/
+http://ubuntu.netforce.hosting/ubuntu/
 http://ubuntu.volia.net/ubuntu-archive/
 #LOC:UG
 http://mirror.renu.ac.ug/ubuntu/
@@ -458,7 +469,6 @@
 http://mirror.cs.pitt.edu/ubuntu/archive/
 http://mirror.enzu.com/ubuntu/
 http://mirror.genesisadaptive.com/ubuntu/
-http://mirror.hmc.edu/ubuntu/
 http://mirror.lstn.net/ubuntu/
 http://mirror.math.princeton.edu/pub/ubuntu/
 http://mirror.math.ucdavis.edu/ubuntu/
@@ -507,11 +517,10 @@
 http://ubuntu.cs.utah.edu/ubuntu/
 http://ubuntu.mirror.constant.com/
 http://ubuntu.mirror.frontiernet.net/ubuntu/
-http://ubuntu.mirror.planet.net/archive/
 http://ubuntu.mirrors.pair.com/archive/
 http://ubuntu.mirrors.tds.net/pub/ubuntu/
 http://ubuntu.osuosl.org/ubuntu/
-http://ubuntu.securedservers.com/
+http://ubuntu.whats-in.space/ubuntu/
 http://us.archive.ubuntu.com/ubuntu/
 http://www.club.cc.cmu.edu/pub/ubuntu/
 http://www.gtlib.gatech.edu/pub/ubuntu/
diff -Nru python-apt-1.8.3/debian/changelog python-apt-1.8.4/debian/changelog
--- python-apt-1.8.3/debian/changelog	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/debian/changelog	2019-03-11 12:49:18.000000000 +0100
@@ -1,3 +1,12 @@
+python-apt (1.8.4) unstable; urgency=medium
+
+  * apt.Cache: Fix (un)locking in various places
+    - Fix (un)locking of archives (Closes: #922416)
+    - Use explicit, more safe locking in update()
+  * Update mirror lists
+
+ -- Julian Andres Klode <jak@debian.org>  Mon, 11 Mar 2019 12:49:18 +0100
+
 python-apt (1.8.3) unstable; urgency=medium
 
   * test_aptsources: Fix test if current distribution does not exist
diff -Nru python-apt-1.8.3/typehinting/apt_pkg.pyi python-apt-1.8.4/typehinting/apt_pkg.pyi
--- python-apt-1.8.3/typehinting/apt_pkg.pyi	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/typehinting/apt_pkg.pyi	2019-03-11 12:49:18.000000000 +0100
@@ -303,6 +303,11 @@
     def __enter__(self) -> None: ...
     def __exit__(self, typ: object, value: object, traceback: object) -> None: ...
     
+class FileLock():
+    def __init__(self, path: str) -> None: ...
+    def __enter__(self) -> None: ...
+    def __exit__(self, typ: object, value: object, traceback: object) -> None: ...
+
 def upstream_version(ver: str) -> str: ...
 def get_architectures() -> List[str]: ...    
 def check_dep(pkg_ver: str, dep_op: str, dep_ver: str) -> bool: ...
diff -Nru -w python-apt-1.8.3/apt/cache.py python-apt-1.8.4/apt/cache.py
--- python-apt-1.8.3/apt/cache.py	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/apt/cache.py	2019-03-11 12:49:18.000000000 +0100
@@ -70,6 +70,29 @@
     """Exception that is thrown when the cache is used after close()."""
 
 
+class _WrappedLock(object):
+    """Wraps an apt_pkg.FileLock to raise LockFailedException.
+
+    Initialized using a directory path."""
+
+    def __init__(self, path):
+        # type: (str) -> None
+        self._path = path
+        self._lock = apt_pkg.FileLock(os.path.join(path, "lock"))
+
+    def __enter__(self):
+        # type: () -> None
+        try:
+            return self._lock.__enter__()
+        except apt_pkg.Error as e:
+            raise LockFailedException(("Failed to lock directory %s: %s") %
+                                       (self._path, e))
+
+    def __exit__(self, typ, value, traceback):
+        # type: (object, object, object) -> None
+        return self._lock.__exit__(typ, value, traceback)
+
+
 class Cache(object):
     """Dictionary-like package cache.
 
@@ -135,6 +158,11 @@
             # Call InitSystem so the change to Dir::State::Status is actually
             # recognized (LP: #320665)
             apt_pkg.init_system()
+
+        # Prepare a lock object (context manager for archive lock)
+        archive_dir = apt_pkg.config.find_dir("Dir::Cache::Archives")
+        self._archive_lock = _WrappedLock(archive_dir)
+
         self.open(progress)
 
     def fix_broken(self):
@@ -426,16 +454,6 @@
         # fetched
         return self._run_fetcher(fetcher)
 
-    def _get_archive_lock(self, fetcher):
-        # type: (apt_pkg.Acquire) -> None
-        # get lock
-        archive_dir = apt_pkg.config.find_dir("Dir::Cache::Archives")
-        try:
-            fetcher.get_lock(archive_dir)
-        except apt_pkg.Error as e:
-            raise LockFailedException(("Failed to lock archive directory %s: "
-                                       " %s") % (archive_dir, e))
-
     def fetch_archives(self, progress=None, fetcher=None):
         # type: (AcquireProgress, apt_pkg.Acquire) -> int
         """Fetch the archives for all packages marked for install/upgrade.
@@ -457,8 +475,7 @@
         if fetcher is None:
             fetcher = apt_pkg.Acquire(progress)
 
-        self._get_archive_lock(fetcher)
-
+        with self._archive_lock:
         return self._fetch_archives(fetcher,
                                     apt_pkg.PackageManager(self._depcache))
 
@@ -520,15 +537,11 @@
         sources_list -- Update a alternative sources.list than the default.
         Note that the sources.list.d directory is ignored in this case
         """
-        lockfile = apt_pkg.config.find_dir("Dir::State::Lists") + "lock"
-        lock = apt_pkg.get_lock(lockfile)
-
-        if lock < 0:
-            raise LockFailedException("Failed to lock %s" % lockfile)
-
+        with _WrappedLock(apt_pkg.config.find_dir("Dir::State::Lists")):
         if sources_list:
             old_sources_list = apt_pkg.config.find("Dir::Etc::sourcelist")
-            old_sources_list_d = apt_pkg.config.find("Dir::Etc::sourceparts")
+                old_sources_list_d = (
+                    apt_pkg.config.find("Dir::Etc::sourceparts"))
             old_cleanup = apt_pkg.config.find("APT::List-Cleanup")
             apt_pkg.config.set("Dir::Etc::sourcelist",
                                os.path.abspath(sources_list))
@@ -552,11 +565,13 @@
             else:
                 return res
         finally:
-            os.close(lock)
             if sources_list:
-                apt_pkg.config.set("Dir::Etc::sourcelist", old_sources_list)
-                apt_pkg.config.set("Dir::Etc::sourceparts", old_sources_list_d)
-                apt_pkg.config.set("APT::List-Cleanup", old_cleanup)
+                    apt_pkg.config.set("Dir::Etc::sourcelist",
+                                       old_sources_list)
+                    apt_pkg.config.set("Dir::Etc::sourceparts",
+                                       old_sources_list_d)
+                    apt_pkg.config.set("APT::List-Cleanup",
+                                       old_cleanup)
 
     def install_archives(self, pm, install_progress):
         # type: (apt_pkg.PackageManager, InstallProgress) -> int
@@ -620,8 +635,7 @@
         with apt_pkg.SystemLock():
             pm = apt_pkg.PackageManager(self._depcache)
             fetcher = apt_pkg.Acquire(fetch_progress)
-            self._get_archive_lock(fetcher)
-
+            with self._archive_lock:
             while True:
                 # fetch archives first
                 res = self._fetch_archives(fetcher, pm)
@@ -635,8 +649,9 @@
                 elif res == pm.RESULT_INCOMPLETE:
                     pass
                 else:
-                    raise SystemError("internal-error: unknown result code "
-                                      "from InstallArchives: %s" % res)
+                        raise SystemError("internal-error: unknown result "
+                                          "code from InstallArchives: %s" %
+                                          res)
                 # reload the fetcher for media swaping
                 fetcher.shutdown()
         return (res == pm.RESULT_COMPLETED)
diff -Nru -w python-apt-1.8.3/data/templates/Debian.mirrors python-apt-1.8.4/data/templates/Debian.mirrors
--- python-apt-1.8.3/data/templates/Debian.mirrors	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/data/templates/Debian.mirrors	2019-03-11 12:49:18.000000000 +0100
@@ -219,7 +219,6 @@
 http://mirror.isoc.org.il/pub/debian/
 #LOC:IN
 http://debianmirror.nkn.in/debian/
-http://ftp.iitm.ac.in/debian/
 http://mirror.cse.iitk.ac.in/debian/
 #LOC:IR
 http://debian.asis.io/debian/
@@ -404,7 +403,6 @@
 http://ftp.utexas.edu/debian/
 http://mirror.cc.columbia.edu/debian/
 http://mirror.cogentco.com/debian/
-http://mirror.cs.uwm.edu/debian/
 http://mirror.hmc.edu/debian/
 http://mirror.keystealth.org/debian/
 http://mirror.math.princeton.edu/pub/debian/
diff -Nru -w python-apt-1.8.3/data/templates/Ubuntu.mirrors python-apt-1.8.4/data/templates/Ubuntu.mirrors
--- python-apt-1.8.3/data/templates/Ubuntu.mirrors	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/data/templates/Ubuntu.mirrors	2019-03-11 12:49:18.000000000 +0100
@@ -92,6 +92,7 @@
 http://mirrors.nju.edu.cn/ubuntu/
 http://mirrors.njupt.edu.cn/ubuntu/
 http://mirrors.nwafu.edu.cn/ubuntu/
+http://mirrors.shu.edu.cn/ubuntu/
 http://mirrors.sohu.com/ubuntu/
 http://mirrors.tuna.tsinghua.edu.cn/ubuntu/
 http://mirrors.ustc.edu.cn/ubuntu/
@@ -146,6 +147,7 @@
 http://packages.oth-regensburg.de/ubuntu/
 http://pubmirror01.lwlcom.net/ubuntu/
 http://suse.uni-leipzig.de/pub/releases.ubuntu.com/ubuntu/
+http://ubuntu.cybertips.info/ubuntu/
 http://ubuntu.mirror.lrz.de/ubuntu/
 http://ubuntu.mirror.tudos.de/ubuntu/
 http://ubuntu.unitedcolo.de/ubuntu/
@@ -166,6 +168,7 @@
 ftp://ftp.csuc.cat/ubuntu/archieve/
 http://dafi.inf.um.es/ubuntu/
 http://es-mirrors.evowise.com/ubuntu/
+http://es.mirror.burstable.org/ubuntu/
 http://ftp.caliu.cat/pub/distribucions/ubuntu/archive/
 http://ftp.udc.es/ubuntu/
 http://mirror.tedra.es/ubuntu/
@@ -179,6 +182,7 @@
 http://distrib-coffee.ipsl.jussieu.fr/pub/linux/ubuntu/
 http://fr.archive.ubuntu.com/ubuntu/
 http://ftp.rezopole.net/ubuntu/
+http://mir1.flosoft-servers.net/ubuntu/
 http://mirror.plusserver.com/ubuntu/ubuntu/
 http://mirror.ubuntu.ikoula.com/ubuntu/
 http://mirrors.ircam.fr/pub/ubuntu/archive/
@@ -190,12 +194,12 @@
 http://wwwftp.ciril.fr/pub/linux/ubuntu/archives/
 #LOC:GB
 http://archive.ubuntu.com/ubuntu/
-http://ftp.thunix.org/ubuntu/
 http://ftp.ticklers.org/archive.ubuntu.org/ubuntu/
 http://mirror.as29550.net/archive.ubuntu.com/
 http://mirror.bytemark.co.uk/ubuntu/
 http://mirror.freethought-internet.co.uk/ubuntu/
 http://mirror.mythic-beasts.com/ubuntu/
+http://mirror.ox.ac.uk/sites/archive.ubuntu.com/ubuntu/
 http://mirror.sax.uk.as61049.net/ubuntu/
 http://mirror.sov.uk.goscomb.net/ubuntu/
 http://mirror.vorboss.net/ubuntu-archive/
@@ -221,29 +225,31 @@
 #LOC:HR
 http://hr.archive.ubuntu.com/ubuntu/
 #LOC:HU
-http://ftp.freepark.org/ubuntu/
+http://ftp.fsn.hu/ubuntu/
+http://hu.archive.ubuntu.com/ubuntu/
+http://mirror.niif.hu/ubuntu/
 http://quantum-mirror.hu/mirrors/pub/ubuntu/
 #LOC:ID
 http://buaya.klas.or.id/ubuntu/
-http://kambing.ui.ac.id/ubuntu/
 http://kartolo.sby.datautama.net.id/ubuntu/
 http://kebo.pens.ac.id/ubuntu/
 http://mirror.biznetgio.com/ubuntu/
+http://mirror.deace.id/ubuntu/
 http://mirror.poliwangi.ac.id/ubuntu/
 http://mirror.unej.ac.id/ubuntu/
 http://repo.unpatti.ac.id/ubuntu/
+http://suro.ubaya.ac.id/ubuntu/
 #LOC:IE
 http://ftp.heanet.ie/pub/ubuntu/
 #LOC:IL
 http://mirror.isoc.org.il/pub/ubuntu/
 #LOC:IN
-http://ftp.iitm.ac.in/ubuntu/
 http://mirror.cse.iitk.ac.in/ubuntu/
 http://mirror.pramati.com/ubuntu/
 http://mirrors.piconets.webwerks.in/ubuntu-mirror/ubuntu/
 http://repos.del.extreme-ix.org/ubuntu/
-http://ubuntu.mirror.snu.edu.in/ubuntu/
 #LOC:IR
+http://mirror.aminidc.com/ubuntu/
 http://mirror.armaghan.net/ubuntu/
 http://mirror.iranserver.com/ubuntu/
 http://mirror.rasanegar.com/ubuntu/archive/
@@ -335,9 +341,9 @@
 http://ubuntu.mirror.cambrium.nl/ubuntu/
 http://ubuntu.mirror.true.nl/ubuntu/
 #LOC:NO
-http://archive.mirror.blix.com/ubuntu/
 http://ftp.uninett.no/ubuntu/
 http://no.archive.ubuntu.com/ubuntu/
+http://no.mirrors.blix.com/ubuntu/
 http://ubuntu.uib.no/archive/
 #LOC:NP
 http://ubuntu.ntc.net.np/ubuntu/
@@ -350,6 +356,7 @@
 #LOC:PF
 http://pf.archive.ubuntu.com/ubuntu/
 #LOC:PH
+http://mirror.pregi.net/ubuntu/
 http://mirror.rise.ph/ubuntu/
 #LOC:PK
 http://mirrors.nayatel.com/ubuntu/
@@ -367,6 +374,7 @@
 http://archive.ubuntumirror.dei.uc.pt/ubuntu/
 http://ftp.rnl.tecnico.ulisboa.pt/pub/ubuntu/archive/
 http://glua.ua.pt/pub/ubuntu/
+http://mirrors.ptisp.pt/ubuntu/
 http://mirrors.up.pt/ubuntu/
 #LOC:RO
 http://ftp.gts.lug.ro/ubuntu/
@@ -387,6 +395,8 @@
 http://mirror.truenetwork.ru/ubuntu/
 http://mirror.yandex.ru/ubuntu/
 http://mirrors.powernet.com.ru/ubuntu/
+#LOC:SA
+http://ubuntu.mirrors.isu.net.sa/ubuntu/
 #LOC:SE
 http://ftp.acc.umu.se/ubuntu/
 http://ftp.lysator.liu.se/ubuntu/
@@ -401,6 +411,7 @@
 #LOC:SI
 http://ftp.arnes.si/pub/mirrors/ubuntu/
 #LOC:SK
+http://ftp.energotel.sk/pub/linux/ubuntu/
 http://mirror.vnet.sk/ubuntu/
 http://tux.rainside.sk/ubuntu/
 #LOC:TH
@@ -413,6 +424,7 @@
 #LOC:TN
 http://ubuntu.mirror.tn/ubuntu/
 #LOC:TR
+http://ftp.linux.org.tr/ubuntu/
 http://mirror.idealhosting.net.tr/ubuntu/
 http://mirror.muvhost.com/ubuntu/
 http://mirror.ni.net.tr/ubuntu/
@@ -420,7 +432,6 @@
 http://ubuntu.turhost.com/ubuntu/
 http://ubuntu.vargonen.com/ubuntu/
 #LOC:TW
-http://debian.linux.org.tw/ubuntu/
 http://free.nchc.org.tw/ubuntu/
 http://ftp.ntou.edu.tw/ubuntu/
 http://ftp.tku.edu.tw/ubuntu/
@@ -431,13 +442,13 @@
 http://ubuntu.cs.nctu.edu.tw/ubuntu/
 http://ubuntu.stu.edu.tw/ubuntu/
 #LOC:TZ
-http://deb-mirror.habari.co.tz/ubuntu/
 http://mirror.aptus.co.tz/pub/ubuntuarchive/
 #LOC:UA
 http://mirror.mirohost.net/ubuntu/
 http://ubuntu.colocall.net/ubuntu/
 http://ubuntu.ip-connect.vn.ua/
 http://ubuntu.mirrors.omnilance.com/ubuntu/
+http://ubuntu.netforce.hosting/ubuntu/
 http://ubuntu.volia.net/ubuntu-archive/
 #LOC:UG
 http://mirror.renu.ac.ug/ubuntu/
@@ -458,7 +469,6 @@
 http://mirror.cs.pitt.edu/ubuntu/archive/
 http://mirror.enzu.com/ubuntu/
 http://mirror.genesisadaptive.com/ubuntu/
-http://mirror.hmc.edu/ubuntu/
 http://mirror.lstn.net/ubuntu/
 http://mirror.math.princeton.edu/pub/ubuntu/
 http://mirror.math.ucdavis.edu/ubuntu/
@@ -507,11 +517,10 @@
 http://ubuntu.cs.utah.edu/ubuntu/
 http://ubuntu.mirror.constant.com/
 http://ubuntu.mirror.frontiernet.net/ubuntu/
-http://ubuntu.mirror.planet.net/archive/
 http://ubuntu.mirrors.pair.com/archive/
 http://ubuntu.mirrors.tds.net/pub/ubuntu/
 http://ubuntu.osuosl.org/ubuntu/
-http://ubuntu.securedservers.com/
+http://ubuntu.whats-in.space/ubuntu/
 http://us.archive.ubuntu.com/ubuntu/
 http://www.club.cc.cmu.edu/pub/ubuntu/
 http://www.gtlib.gatech.edu/pub/ubuntu/
diff -Nru -w python-apt-1.8.3/debian/changelog python-apt-1.8.4/debian/changelog
--- python-apt-1.8.3/debian/changelog	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/debian/changelog	2019-03-11 12:49:18.000000000 +0100
@@ -1,3 +1,12 @@
+python-apt (1.8.4) unstable; urgency=medium
+
+  * apt.Cache: Fix (un)locking in various places
+    - Fix (un)locking of archives (Closes: #922416)
+    - Use explicit, more safe locking in update()
+  * Update mirror lists
+
+ -- Julian Andres Klode <jak@debian.org>  Mon, 11 Mar 2019 12:49:18 +0100
+
 python-apt (1.8.3) unstable; urgency=medium
 
   * test_aptsources: Fix test if current distribution does not exist
diff -Nru -w python-apt-1.8.3/typehinting/apt_pkg.pyi python-apt-1.8.4/typehinting/apt_pkg.pyi
--- python-apt-1.8.3/typehinting/apt_pkg.pyi	2019-02-04 12:50:31.000000000 +0100
+++ python-apt-1.8.4/typehinting/apt_pkg.pyi	2019-03-11 12:49:18.000000000 +0100
@@ -303,6 +303,11 @@
     def __enter__(self) -> None: ...
     def __exit__(self, typ: object, value: object, traceback: object) -> None: ...
     
+class FileLock():
+    def __init__(self, path: str) -> None: ...
+    def __enter__(self) -> None: ...
+    def __exit__(self, typ: object, value: object, traceback: object) -> None: ...
+
 def upstream_version(ver: str) -> str: ...
 def get_architectures() -> List[str]: ...    
 def check_dep(pkg_ver: str, dep_op: str, dep_ver: str) -> bool: ...

Reply to: