diff -pruN 0.51/axi/indexer.py 0.51ubuntu1/axi/indexer.py
--- 0.51/axi/indexer.py	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/axi/indexer.py	2020-03-27 11:05:54.000000000 +0000
@@ -565,6 +565,11 @@ class Indexer(object):
         for idx, pkg in enumerate(cache):
             if not pkg.candidate:
                 continue
+            # multiarch: do not index foreign arch if there is a native
+            # archive version available (unless the pkg is installed)
+            if (not pkg.installed and
+                ":" in pkg.name and pkg.name.split(":")[0] in cache):
+                continue
             # Print progress
             if idx % 200 == 0: self.progress.progress(100*idx/count)
             yield self.get_document_from_apt(pkg)
@@ -639,7 +644,11 @@ class Indexer(object):
         """
         Update the index
         """
-        db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OPEN)
+        try:
+            db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OPEN)
+        except xapian.DatabaseLockError as e:
+            self.progress.warning("DB Update failed, database locked")
+            return
         cache = self.aptcache()
         count = len(cache)
 
diff -pruN 0.51/debian/changelog 0.51ubuntu1/debian/changelog
--- 0.51/debian/changelog	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/debian/changelog	2020-03-27 11:20:11.000000000 +0000
@@ -1,3 +1,24 @@
+apt-xapian-index (0.51ubuntu1) focal; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - Prefer native packages over foreign packages.
+    - Do not crash if the DB is already locked.
+    - Do not modify the DB "in-place" with --update
+    - debian/patches/01_axi_cjk_support.patch:
+      - Activate the CJK support when indexing the database.
+    - debian/patches/02_axi-pkgname-mangled-term.patch:
+      - add XPM term that contains a mangled version of the pkgname.
+    - plugins/app-install.py:
+      - Ignore file not found errors due to a race condition.
+    - debian/patches/06_32bit_sizes.patch: Watch out for package sizes that
+      don't fit in 32 bits.
+    - debian/patches/07_glib_import.patch: Fix the import of GLib and GObject.
+    - Bump the minimum version for removal of the dbus service; this delta can
+      be dropped after the release of Ubuntu 20.04.
+    - Build with quilt
+
+ -- Julian Andres Klode <juliank@ubuntu.com>  Fri, 27 Mar 2020 12:20:11 +0100
+
 apt-xapian-index (0.51) unstable; urgency=medium
 
   * QA upload.
@@ -48,6 +69,63 @@ apt-xapian-index (0.50) unstable; urgenc
 
  -- Paul Wise <pabs@debian.org>  Sat, 27 Jul 2019 19:01:18 +0800
 
+apt-xapian-index (0.49ubuntu3) eoan; urgency=medium
+
+  * Port to APT 1.9
+  * Do not pass memonly=True to apt.Cache, this sometimes prevents plugins from
+    reading the mtime of the cache file - depending on whether they were initialized
+    before or after the cache was generated; because apt.Cache() unsets the pkgcache
+    option and the plugins can thus not find the cache file anymore.
+
+ -- Julian Andres Klode <juliank@ubuntu.com>  Thu, 27 Jun 2019 11:35:49 +0200
+
+apt-xapian-index (0.49ubuntu2) eoan; urgency=medium
+
+  * debian/patches: rebase, so that python3 compatibility is first and
+    upstreamable.
+
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Tue, 07 May 2019 22:42:01 -0700
+
+apt-xapian-index (0.49ubuntu1) eoan; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - Prefer native packages over foreign packages.
+    - Do not crash if the DB is already locked.
+    - Do not modify the DB "in-place" with --update
+    - debian/patches/01_axi_cjk_support.patch:
+      - Activate the CJK support when indexing the database.
+    - debian/patches/02_axi-pkgname-mangled-term.patch:
+      - add XPM term that contains a mangled version of the pkgname.
+    - plugins/app-install.py:
+      - Ignore file not found errors due to a race condition.
+    - debian/compat: Bump to version 9.
+    - debian/control:
+      - Bump debhelper version to >= 9.
+      - Switch dependencies to their Python 3 version.
+      - Use X-Python3-Version instead.
+    - debian/rules:
+      - Use --with=python3 and --build-system=pybuild
+      - Add override_dh_python3 to force /usr/bin/python3 shebang.
+      - Run the tests in an override_dh_auto_test target.
+    - debian/patches/04_bilingual.patch: Port the code to work in Python
+      2.7, 3.4, and 3.5.
+    - debian/patches/05_python3.patch: Switch the default to Python 3.
+    - debian/patches/06_32bit_sizes.patch: Watch out for package sizes that
+      don't fit in 32 bits.
+    - debian/patches/07_glib_import.patch: Fix the import of GLib and GObject.
+  * Dropped changes, no longer needed:
+    - remove the dbus service; software-center which used it is no longer in
+      Ubuntu.
+    - debian/patches/03_stick_to_main.patch: drop; we are not confined to
+      main now that this package is in universe.
+  * Dropped changes, included in Debian:
+    - debian/postinst:
+      - Do not build the DB in the postinst.
+  * Bump the minimum version for removal of the dbus service; this delta can
+    be dropped after the release of Ubuntu 20.04.
+
+ -- Steve Langasek <steve.langasek@ubuntu.com>  Tue, 07 May 2019 21:27:14 -0700
+
 apt-xapian-index (0.49) unstable; urgency=medium
 
   * QA upload.
@@ -86,6 +164,142 @@ apt-xapian-index (0.47+nmu1) unstable; u
 
  -- Sven Joachim <svenjoac@gmx.de>  Fri, 13 Nov 2015 21:06:50 +0100
 
+apt-xapian-index (0.47ubuntu13) zesty; urgency=medium
+
+  * d/control: Change the dependency on python3-xapian to a versioned one so
+    that on upgrades the package will be installed and python3-xapian1.3 will
+    be removed. (LP: #1680090)
+
+ -- Brian Murray <brian@ubuntu.com>  Wed, 12 Apr 2017 09:10:22 -0700
+
+apt-xapian-index (0.47ubuntu12) zesty; urgency=medium
+
+  * d/control: Drop the explicit Depends/Build-Depends on
+    python3-xapian1.3 since that was a development snapshot we only used
+    in our port to Python 3.  Straight up python3-xapian (1.4) has
+    everything we need.  (LP: #1660216)
+
+ -- Barry Warsaw <barry@ubuntu.com>  Mon, 03 Apr 2017 13:29:18 -0400
+
+apt-xapian-index (0.47ubuntu11) yakkety; urgency=medium
+
+  * debian/patches/05_python3.patch:
+    - properly apply the change by Carlo Vanini, previous upload was rubbish
+
+ -- Harald Sitter <sitter@kde.org>  Mon, 15 Aug 2016 14:39:37 +0200
+
+apt-xapian-index (0.47ubuntu10) yakkety; urgency=medium
+
+  * debian/patches/05_python3.patch:
+    - string.split has been removed in python3
+    - open subprocess stdout as text stream
+    - Thanks to Carlo Vanini for the patch.
+
+ -- Brian Murray <brian@ubuntu.com>  Tue, 09 Aug 2016 16:43:22 -0700
+
+apt-xapian-index (0.47ubuntu9) yakkety; urgency=medium
+
+  * debian/patches/07_glib_import.patch: Fix the import of GLib and GObject.
+    (LP: #1579834)
+
+ -- Carlo Vanini <silhusk@gmail.com>  Fri, 22 Jul 2016 13:25:11 -0700
+
+apt-xapian-index (0.47ubuntu8) xenial; urgency=medium
+
+  * debian/patches/05_python3.patch: del the indexer instance explicitly
+    before sys.exit(), so that it gets decrefed and freed before Python's
+    implicit shutdown machinery can potentially leave an empty os module for
+    ServerProgress.__del__() to find.  (LP: #1530518)
+
+ -- Barry Warsaw <barry@ubuntu.com>  Wed, 13 Apr 2016 17:36:22 -0400
+
+apt-xapian-index (0.47ubuntu7) xenial; urgency=medium
+
+  * debian/patches/04_bilingual.patch: Make some Python 2-only constructs
+    in update-apt-xapian-index-dbus bilingual, and add a missing import.
+    (LP: #1541407)
+
+ -- Barry Warsaw <barry@ubuntu.com>  Wed, 03 Feb 2016 09:54:17 -0500
+
+apt-xapian-index (0.47ubuntu6) xenial; urgency=medium
+
+  * debian/patches/06_32bit_sizes.patch: Watch out for package sizes that
+    don't fit in 32 bits.  (LP: #1527745)
+
+ -- Barry Warsaw <barry@ubuntu.com>  Fri, 18 Dec 2015 16:47:43 -0500
+
+apt-xapian-index (0.47ubuntu5) xenial; urgency=medium
+
+  * debian/patches/04_bilingual.patch: When using --force --update on
+    update-apt-xapian-index, be sure package names passed to python3-apt
+    are strings, not bytes.  (LP: #1526267)
+
+ -- Barry Warsaw <barry@ubuntu.com>  Wed, 16 Dec 2015 14:12:44 -0500
+
+apt-xapian-index (0.47ubuntu4) xenial; urgency=medium
+
+  * debian/patches/04_bilingual.patch: Be sure to open files passed to
+    pickle.{load,dump}() in binary mode.
+
+ -- Barry Warsaw <barry@ubuntu.com>  Tue, 15 Dec 2015 16:23:18 -0500
+
+apt-xapian-index (0.47ubuntu3) xenial; urgency=medium
+
+  * debian/patches:
+    - 04_bilingual.patch: Port the code to work in Python 2.7, 3.4, and 3.5.
+    - 05_python3.patch: Switch the default to Python 3.  (LP: #1516688)
+  * debian/compat: Bump to version 9.
+  * debian/control:
+    - Bump debhelper version to >= 9.
+    - Switch dependencies to their Python 3 version.
+    - Use X-Python3-Version instead.
+  * debian/rules:
+    - Use --with=python3 and --build-system=pybuild
+    - Add override_dh_python3 to force /usr/bin/python3 shebang.
+    - Run the tests in an override_dh_auto_test target.
+
+ -- Barry Warsaw <barry@ubuntu.com>  Tue, 24 Nov 2015 11:13:01 -0500
+
+apt-xapian-index (0.47ubuntu2) xenial; urgency=medium
+
+  * debian/patches/03_stick_to_main.patch: Use libdbus-1-dev instead of
+    libept-dev as a test package since the latter is not in main, which
+    will cause FTBFS in Ubuntu.
+
+ -- Barry Warsaw <barry@ubuntu.com>  Mon, 23 Nov 2015 17:29:00 -0500
+
+apt-xapian-index (0.47ubuntu1) xenial; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - Prefer native packages over foreign packages.
+    - Do not crash if the DB is already locked. (LP: #590998)
+    - Do not modify the DB "in-place" with --update
+    - debian/patches/01_axi_cjk_support.patch:
+      - Activate the CJK support when indexing the database.
+    - debian/patches/02_axi-pkgname-mangled-term.patch:
+      - add XPM term that contains a mangled version of the pkgname.
+    - debian/postinst:
+      - Do not build the DB in the postinst.
+    - debian/rules:
+      - quilt with dh --with python2
+    - plugins/app-install.py:
+      - Ignore file not found errors due to a race condition. (LP: #752195)
+    - Restore the D-Bus API since software-center is not yet removed from
+      Ubuntu:
+      - Re-add the update-apt-xapian-index-dbus script.
+      - Re-add the data directory containing the D-Bus configuration files.
+      - Re-add the d/dirs entries for the D-Bus files.
+      - Re-add the d/rules to install the D-Bus files.
+      - Remove the d/preinst, edit the d/postinst and d/postrm scripts since we
+        don't want to remove the D-Bus conffile.
+  * Dropped:
+    - debian/patches/04_catch_invalid_desktop_file.patch: no longer needed
+    - debian/patches/03_policykit_translations.patch: Applied directly to
+      Ubuntu copy of D-Bus files.
+    - debian/CVE-2013-1064.patch: Applied directly to the Ubuntu copy.
+
+ -- Barry Warsaw <barry@ubuntu.com>  Mon, 23 Nov 2015 10:56:00 -0500
+
 apt-xapian-index (0.47) unstable; urgency=low
 
   [ Enrico Zini ]
@@ -100,6 +314,31 @@ apt-xapian-index (0.47) unstable; urgenc
 
  -- Enrico Zini <enrico@debian.org>  Sun, 24 Aug 2014 10:44:58 -0700
 
+apt-xapian-index (0.46ubuntu1) utopic; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - prefer native packages over foreign packages 
+    - do not crash if the DB is already locked (LP: #590998)
+    - do not modify the DB "in-place" with --update
+    - debian/patches/01_axi_cjk_support.patch:
+      - Activate the CJK support when indexing the database
+    - debian/patches/02_axi-pkgname-mangled-term.patch:
+      - add XPM term that contains a mangled version of the pkgname
+    - debian/patches/03_policykit_translations.patch: 
+      - remove underscores from description
+    - debian/patches/CVE-2013-1064.patch:
+      + pass system-bus-name as a subject
+    - debian/postinst:
+      - do not build the DB in the postinst
+    - debian/rules:
+      - quilt with dh --with python2
+    - plugins/app-install.py:
+      - ignore file not found errors due to a race condition (LP: #752195)
+  * Drop:
+    - debian/patches/04_catch_invalid_desktop_file.patch: no longer needed
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Tue, 03 Jun 2014 21:29:13 +0200
+
 apt-xapian-index (0.46) unstable; urgency=low
 
   * Fixed schrödinbug in app-install-data locale language parsing
@@ -113,6 +352,50 @@ apt-xapian-index (0.46) unstable; urgenc
 
  -- Enrico Zini <enrico@debian.org>  Fri, 23 Nov 2012 21:46:48 +0100
 
+apt-xapian-index (0.45ubuntu4) trusty; urgency=medium
+
+  * Rebuild to drop files installed into /usr/share/pyshared.
+
+ -- Matthias Klose <doko@ubuntu.com>  Sun, 23 Feb 2014 13:46:10 +0000
+
+apt-xapian-index (0.45ubuntu3) saucy; urgency=low
+
+  * SECURITY UPDATE: possible privilege escalation via policykit UID lookup
+    race.
+    - debian/patches/CVE-2013-1064.patch: pass system-bus-name as a subject
+      instead of pid so policykit can get the information from the system
+      bus in update-apt-xapian-index-dbus.
+    - CVE-2013-1064
+
+ -- Marc Deslauriers <marc.deslauriers@ubuntu.com>  Wed, 18 Sep 2013 12:40:20 -0400
+
+apt-xapian-index (0.45ubuntu2) raring; urgency=low
+
+  * debian/patches/01_axi_cjk_support.patch:
+    - updated for the new version, fix the build
+
+  [ Thomas Kluyver ]
+  * debian/patches/04_catch_invalid_desktop_file.patch: Catch an exception
+    from parsing invalid .desktop files for app-install.
+
+ -- Sebastien Bacher <seb128@ubuntu.com>  Tue, 27 Nov 2012 19:59:39 +0100
+
+apt-xapian-index (0.45ubuntu1) raring; urgency=low
+
+  * Merge from Debian unstable.  Remaining changes:
+    - prefer native packages over foreign packages 
+    - do not crash if the DB is already locked (LP: #590998)
+    - do not modify the DB "in-place" with --update
+    - debian/patches/01_axi_cjk_support.patch:
+      - Activate the CJK support when indexing the database
+    - Don't call update-python-modules in the postinst. LP: #856627.
+    - fix spelling errors
+    - add XPM term that contains a mangled version of the pkgname
+    - debian/patches/03_policykit_translations.patch: 
+     - remove underscores from description
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Tue, 27 Nov 2012 16:40:11 +0100
+
 apt-xapian-index (0.45) unstable; urgency=low
 
   * Gracefully deal with plugins failing in their info() function.
@@ -120,6 +403,71 @@ apt-xapian-index (0.45) unstable; urgenc
 
  -- Enrico Zini <enrico@debian.org>  Wed, 28 Dec 2011 14:34:39 +0100
 
+apt-xapian-index (0.44ubuntu8) raring; urgency=low
+
+  * debian/patches/03_policykit_translations.patch: remove underscores from
+    description and message tags in the policykit policy, since there are no
+    translations currently being done for apt-xapian-index and this causes
+    error messages to be spewed when the policy file gets parsed.
+
+ -- Mathieu Trudel-Lapierre <mathieu-tl@ubuntu.com>  Wed, 31 Oct 2012 10:24:35 +0100
+
+apt-xapian-index (0.44ubuntu7) quantal; urgency=low
+
+  * add XPM term that contains a mangled version of the pkgname where
+    all "-" are replaced with "_" to workaround that the queryparser
+    considers "-" a special char
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 17 Aug 2012 13:35:36 +0200
+
+apt-xapian-index (0.44ubuntu6) quantal; urgency=low
+
+  * Fixed two Spelling errors (allows to changed to allows one to)
+    (maintan changed to maintain) in the debian/control file
+
+ -- Chad Dunlap <cldunlap1@gmail.com>  Mon, 13 Aug 2012 13:46:19 -0400
+
+apt-xapian-index (0.44ubuntu5) precise; urgency=low
+
+  * Rebuild to drop python2.6 dependencies.
+
+ -- Matthias Klose <doko@ubuntu.com>  Sat, 31 Dec 2011 02:00:43 +0000
+
+apt-xapian-index (0.44ubuntu4) oneiric; urgency=low
+
+  * Don't call update-python-modules in the postinst. LP: #856627.
+
+ -- Matthias Klose <doko@ubuntu.com>  Sat, 24 Sep 2011 14:42:18 +0200
+
+apt-xapian-index (0.44ubuntu3) oneiric; urgency=low
+
+  * axi/indexer.py:
+    - prefer native packages over foreign packages (unless there
+      is no native version or the foreign package is installed)
+      (LP: #830508)
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Wed, 21 Sep 2011 13:48:47 +0200
+
+apt-xapian-index (0.44ubuntu2) oneiric; urgency=low
+
+  * debian/patches/01_axi_cjk_support.patch:
+    - Activate the CJK support when indexing the database
+  * debian/control, debian/rules:
+    - add quilt for above patch
+
+ -- Didier Roche <didrocks@ubuntu.com>  Thu, 01 Sep 2011 18:26:04 +0200
+
+apt-xapian-index (0.44ubuntu1) oneiric; urgency=low
+
+  * Merge from debian unstable.  Remaining changes:
+    - do not crash if the DB is already locked (LP: #590998)
+    - move to dh_python2
+    - do not modify the DB "in-place" with --update
+  * ignore file not found errors when checking for the mtime
+    (LP: #752195), thanks to Brian Murray
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Tue, 26 Jul 2011 09:02:49 +0200
+
 apt-xapian-index (0.44) unstable; urgency=low
 
   * Applied trailing comma patch by Cédric Boutillier. Closes: #630774
@@ -140,6 +488,22 @@ apt-xapian-index (0.44) unstable; urgenc
 
  -- Enrico Zini <enrico@debian.org>  Wed, 22 Jun 2011 00:50:25 +0200
 
+apt-xapian-index (0.43ubuntu1) oneiric; urgency=low
+
+  * Merge from debian unstable.  Remaining changes:
+    - when upgrading, ensure the index is fully rebuild (in the
+      background) to ensure that we get updated information in
+      /var/lib/apt-xapian-index/{index.values} and that the index
+      fully utilizes the new plugins (LP: #646018)
+    - use ionice for the index building
+    - do not crash if the DB is already locked (LP: #590998)
+    - data/org.debian.AptXapianIndex.conf: fix policy
+    - move to dh_python2
+    - update-apt-xapian-index-dbus:
+      + fix type of "start-time" for policykit (LP: #675533)
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 17 Jun 2011 10:51:30 +0200
+
 apt-xapian-index (0.43) unstable; urgency=low
 
   * Implemented axi-cache info. Closes: #602600
@@ -157,6 +521,62 @@ apt-xapian-index (0.42) unstable; urgenc
 
  -- Enrico Zini <enrico@debian.org>  Wed, 09 Mar 2011 14:08:34 +0000
 
+apt-xapian-index (0.41ubuntu7) oneiric; urgency=low
+
+  * switch from python-support to dh_python2
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 10 Jun 2011 13:22:42 +0200
+
+apt-xapian-index (0.41ubuntu6) natty; urgency=low
+
+  * debian/cron.weekly:
+    - do not modify the DB "in-place" with --update to avoid
+      software-center seeing a corrupted database when it has
+      it open at the same time
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Mon, 18 Apr 2011 11:15:27 +0200
+
+apt-xapian-index (0.41ubuntu5) natty; urgency=low
+
+  * update-apt-xapian-index:
+    - do not crash if the DB is already logged, thanks to Martin Schaaf
+      (LP: #590998)
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Fri, 28 Jan 2011 14:29:21 +0100
+
+apt-xapian-index (0.41ubuntu4) natty; urgency=low
+
+  * data/org.debian.AptXapianIndex.conf:
+    - fix typo
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 27 Jan 2011 15:57:50 +0100
+
+apt-xapian-index (0.41ubuntu3) natty; urgency=low
+
+  * data/org.debian.AptXapianIndex.conf:
+    - update policy to avoid warning in software-center on
+      startup
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 27 Jan 2011 15:39:54 +0100
+
+apt-xapian-index (0.41ubuntu2) natty; urgency=low
+
+  * update-apt-xapian-index-dbus:
+    - fix type of "start-time" for policykit (LP: #675533)
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Wed, 01 Dec 2010 17:45:52 +0100
+
+apt-xapian-index (0.41ubuntu1) natty; urgency=low
+
+  * Merge from debian unstable.  Remaining changes:
+    - when upgrading, ensure the index is fully rebuild (in the
+      background) to ensure that we get updated information in
+      /var/lib/apt-xapian-index/{index.values} and that the index
+      fully utilizes the new plugins (LP: #646018)
+    - use ionice for the index building
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Wed, 17 Nov 2010 17:50:20 +0100
+
 apt-xapian-index (0.41) unstable; urgency=low
 
   * Fixed typo in dbus config
@@ -172,6 +592,16 @@ apt-xapian-index (0.40) unstable; urgenc
 
  -- Enrico Zini <enrico@debian.org>  Sun, 03 Oct 2010 11:39:28 +0100
 
+apt-xapian-index (0.39ubuntu1) maverick; urgency=low
+
+  * debian/postinst:
+    - when upgrading, ensure the index is fully rebuild (in the
+      background) to ensure that we get updated information in
+      /var/lib/apt-xapian-index/{index.values} and that the index
+      fully utilizes the new plugins (LP: #646018)
+
+ -- Michael Vogt <michael.vogt@ubuntu.com>  Thu, 23 Sep 2010 16:04:11 +0200
+
 apt-xapian-index (0.39) unstable; urgency=low
 
   [ Enrico Zini ]
@@ -530,3 +960,4 @@ apt-xapian-index (0.1) experimental; urg
     system-wide index of Debian package metadata.
 
  -- Enrico Zini <enrico@debian.org>  Tue, 16 Oct 2007 12:20:43 +0100
+
diff -pruN 0.51/debian/control 0.51ubuntu1/debian/control
--- 0.51/debian/control	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/debian/control	2020-03-27 10:47:40.000000000 +0000
@@ -1,9 +1,11 @@
 Source: apt-xapian-index
 Section: admin
 Priority: optional
-Maintainer: Debian QA Group <packages@qa.debian.org>
+Maintainer: Ubuntu Developers <ubuntu-devel-discuss@lists.ubuntu.com>
+XSBC-Original-Maintainer: Debian QA Group <packages@qa.debian.org>
 Build-Depends:
  debhelper-compat (= 12),
+ quilt,
 Build-Depends-Indep:
  bash-completion (>= 1:2.1-4.2~),
  dh-python,
diff -pruN 0.51/debian/cron.weekly 0.51ubuntu1/debian/cron.weekly
--- 0.51/debian/cron.weekly	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/debian/cron.weekly	2020-03-08 15:15:54.000000000 +0000
@@ -23,8 +23,8 @@ if [ -x "$CMD" ]
 then
 	if [ -x "$IONICE" ]
 	then
-		nice -n 19 $IONICE -c 3 $CMD --update --quiet
+		nice -n 19 $IONICE -c 3 $CMD --quiet
 	else
-		nice -n 19 $CMD --update --quiet
+		nice -n 19 $CMD --quiet
 	fi
 fi
diff -pruN 0.51/debian/patches/01_axi_cjk_support.patch 0.51ubuntu1/debian/patches/01_axi_cjk_support.patch
--- 0.51/debian/patches/01_axi_cjk_support.patch	1970-01-01 00:00:00.000000000 +0000
+++ 0.51ubuntu1/debian/patches/01_axi_cjk_support.patch	2019-06-27 09:35:49.000000000 +0000
@@ -0,0 +1,150 @@
+=== modified file 'axi-cache'
+Index: apt-xapian-index-0.49ubuntu2/axi-cache
+===================================================================
+--- apt-xapian-index-0.49ubuntu2.orig/axi-cache
++++ apt-xapian-index-0.49ubuntu2/axi-cache
+@@ -43,6 +43,9 @@
+ XDG_CACHE_HOME = os.environ.get("XDG_CACHE_HOME", os.path.expanduser("~/.cache"))
+ CACHEFILE = os.path.join(XDG_CACHE_HOME, "axi-cache.state")
+ 
++# Activate support for the CJK tokenizer
++os.environ["XAPIAN_CJK_NGRAM"] = "1"
++
+ try:
+     from ConfigParser import RawConfigParser
+     import re
+Index: apt-xapian-index-0.49ubuntu2/axi/indexer.py
+===================================================================
+--- apt-xapian-index-0.49ubuntu2.orig/axi/indexer.py
++++ apt-xapian-index-0.49ubuntu2/axi/indexer.py
+@@ -641,6 +641,9 @@
+         self.progress.end()
+         return unchanged, outdated, obsolete
+ 
++    def is_cjk_enabled (self):
++        return "XAPIAN_CJK_NGRAM" in os.environ
++
+     def updateIndex(self, pathname):
+         """
+         Update the index
+@@ -650,6 +653,12 @@
+         except xapian.DatabaseLockError:
+             self.progress.warning("DB Update failed, database locked")
+             return
++
++        # Make sure the index CJK-compatible
++        if self.is_cjk_enabled() and db.get_metadata("cjk_ngram") != b"1":
++            self.progress.notice("The index %s is not CJK-compatible, rebuilding it" % axi.XAPIANINDEX)
++            return self.rebuild()
++
+         cache = self.aptcache()
+         count = len(cache)
+ 
+@@ -710,6 +719,11 @@
+ 
+         # Create a new Xapian index
+         db = xapian.WritableDatabase(pathname, xapian.DB_CREATE_OR_OVERWRITE)
++
++        # Mark the new index as CJK-enabled if relevant
++        if self.is_cjk_enabled():
++            db.set_metadata("cjk_ngram", "1")
++
+         # It seems to be faster without transactions, at the moment
+         #db.begin_transaction(False)
+ 
+Index: apt-xapian-index-0.49ubuntu2/test/test_indexer.py
+===================================================================
+--- apt-xapian-index-0.49ubuntu2.orig/test/test_indexer.py
++++ apt-xapian-index-0.49ubuntu2/test/test_indexer.py
+@@ -6,6 +6,7 @@
+ import shutil
+ import subprocess
+ import tools
++import xapian
+ 
+ def smallcache(pkglist=["apt", "libept-dev", "gedit"]):
+     class sc(object):
+@@ -61,6 +62,11 @@
+         # Ensure that we have an index
+         self.assertCleanIndex()
+ 
++    def testAptRebuildWithCJK(self):
++        os.environ["XAPIAN_CJK_NGRAM"] = "1"
++        self.testAptRebuild()
++        del os.environ["XAPIAN_CJK_NGRAM"]
++
+     def testDeb822Rebuild(self):
+         pkgfile = os.path.join(axi.XAPIANDBPATH, "packages")
+         subprocess.check_call("apt-cache show apt libept-dev gedit > " + pkgfile, shell=True)
+@@ -117,6 +123,55 @@
+         # Ensure that we did not create a new index
+         self.assertEqual(open(axi.XAPIANINDEX).read(), curidx)
+ 
++    def testIncrementalRebuildWithCJK(self):
++        os.environ["XAPIAN_CJK_NGRAM"] = "1"
++        self.testIncrementalRebuild()
++        del os.environ["XAPIAN_CJK_NGRAM"]
++
++    def testIncrementalRebuildUpgradingtoCJK(self):
++        # Perform the initial indexing without CJK enabled
++        self.assertFalse("XAPIAN_CJK_NGRAM" in os.environ)
++        progress = axi.indexer.SilentProgress()
++        pre_indexer = axi.indexer.Indexer(progress, True)
++        pre_indexer._test_wrap_apt_cache(smallcache(["apt", "libept-dev", "gedit"]))
++        self.assert_(pre_indexer.lock())
++        self.assert_(pre_indexer.setupIndexing())
++        pre_indexer.rebuild()
++        pre_indexer = None
++        curidx = open(axi.XAPIANINDEX).read()
++
++        # Ensure that we have an index
++        self.assertCleanIndex()
++
++        # Prepare an incremental update
++        self.indexer._test_wrap_apt_cache(smallcache(["apt", "coreutils", "gedit"]))
++
++        # No other indexers are running, ensure lock succeeds
++        self.assert_(self.indexer.lock())
++
++        # An index exists the plugin modification timestamps are the same, so
++        # we need to force the indexer to run
++        self.assert_(not self.indexer.setupIndexing())
++        self.assert_(self.indexer.setupIndexing(force=True))
++
++        # Perform a rebuild with CJK enabled
++        os.environ["XAPIAN_CJK_NGRAM"] = "1"
++        self.indexer.incrementalUpdate()
++        del os.environ["XAPIAN_CJK_NGRAM"]
++
++        # Close the indexer
++        self.indexer = None
++
++        # Ensure that we have an index
++        self.assertCleanIndex()
++
++        # Ensure that we created a new index (because we reindexed to get CJK)
++        self.assertNotEqual(open(axi.XAPIANINDEX).read(), curidx)
++
++        # Double check that we set the CJK flag in the index
++        db = xapian.Database(axi.XAPIANINDEX)
++        self.assertEqual(db.get_metadata("cjk_ngram"), b"1")
++
+     def testIncrementalRebuildFromEmpty(self):
+         # Prepare an incremental update
+         self.indexer._test_wrap_apt_cache(smallcache())
+Index: apt-xapian-index-0.49ubuntu2/update-apt-xapian-index
+===================================================================
+--- apt-xapian-index-0.49ubuntu2.orig/update-apt-xapian-index
++++ apt-xapian-index-0.49ubuntu2/update-apt-xapian-index
+@@ -24,6 +24,11 @@
+ 
+ from __future__ import print_function
+ 
++import os
++# Activate support for the CJK tokenizer
++os.environ["XAPIAN_CJK_NGRAM"] = "1"
++
++
+ #
+ # Main program body
+ #
diff -pruN 0.51/debian/patches/02_axi-pkgname-mangled-term.patch 0.51ubuntu1/debian/patches/02_axi-pkgname-mangled-term.patch
--- 0.51/debian/patches/02_axi-pkgname-mangled-term.patch	1970-01-01 00:00:00.000000000 +0000
+++ 0.51ubuntu1/debian/patches/02_axi-pkgname-mangled-term.patch	2019-06-27 09:35:49.000000000 +0000
@@ -0,0 +1,13 @@
+--- a/axi/indexer.py
++++ b/axi/indexer.py
+@@ -531,6 +531,10 @@
+         # Index the package name with a special prefix, to be able to find this
+         # document by exact package name match
+         document.add_term("XP"+pkg.name)
++        # the query parser is very unhappy about "-" in the pkgname, this
++        # breaks e.g. FLAG_WILDCARD based matching, so we add a mangled
++        # name here
++        document.add_term("XPM"+pkg.name.replace("-","_"))
+         # Have all the various plugins index their things
+         for addon in self.plugins:
+             addon.obj.index(document, pkg)
diff -pruN 0.51/debian/patches/06_32bit_sizes.patch 0.51ubuntu1/debian/patches/06_32bit_sizes.patch
--- 0.51/debian/patches/06_32bit_sizes.patch	1970-01-01 00:00:00.000000000 +0000
+++ 0.51ubuntu1/debian/patches/06_32bit_sizes.patch	2019-06-27 09:35:49.000000000 +0000
@@ -0,0 +1,47 @@
+Description: On 32 bit systems, large packages like  astrometry-data-2mass-00
+ can have an installed size that doesn't fit in 32 bits, generating an
+ OverflowError.  Xapian doesn't catch this and thus returns a value with an
+ exception set, causing a chained SystemError.  In either case, catch the
+ exception and treat it as if the size is -1, i.e. don't add it to the
+ document.
+Author: Barry Warsaw <barry@ubuntu.com>
+Bug: https://bugs.launchpad.net/ubuntu/+source/xapian1.3-bindings/+bug/1527745
+
+--- a/plugins/sizes.py
++++ b/plugins/sizes.py
+@@ -95,9 +95,15 @@
+             return
+ 
+         if self.val_inst_size != -1:
+-            document.add_value(self.val_inst_size, xapian.sortable_serialise(instSize));
++            try:
++                document.add_value(self.val_inst_size, xapian.sortable_serialise(instSize));
++            except (OverflowError, SystemError):
++                pass
+         if self.val_pkg_size != -1:
+-            document.add_value(self.val_pkg_size, xapian.sortable_serialise(pkgSize));
++            try:
++                document.add_value(self.val_pkg_size, xapian.sortable_serialise(pkgSize));
++            except (OverflowError, SystemError):
++                pass
+ 
+     def indexDeb822(self, document, pkg):
+         """
+@@ -116,9 +122,15 @@
+             return
+ 
+         if self.val_inst_size != -1:
+-            document.add_value(self.val_inst_size, xapian.sortable_serialise(instSize));
++            try:
++                document.add_value(self.val_inst_size, xapian.sortable_serialise(instSize));
++            except (OverflowError, SystemError):
++                pass
+         if self.val_pkg_size != -1:
+-            document.add_value(self.val_pkg_size, xapian.sortable_serialise(pkgSize));
++            try:
++                document.add_value(self.val_pkg_size, xapian.sortable_serialise(pkgSize));
++            except (OverflowError, SystemError):
++                pass
+ 
+ def init():
+     """
diff -pruN 0.51/debian/patches/07_glib_import.patch 0.51ubuntu1/debian/patches/07_glib_import.patch
--- 0.51/debian/patches/07_glib_import.patch	1970-01-01 00:00:00.000000000 +0000
+++ 0.51ubuntu1/debian/patches/07_glib_import.patch	2019-06-27 09:35:49.000000000 +0000
@@ -0,0 +1,20 @@
+## Description: fix import of GLib and GObject
+## Author: Carlo Vanini <silhusk@gmail.com>
+## Bug-Ubuntu: https://bugs.launchpad.net/bugs/1579834
+## Last-Update: 2016-07-07
+Index: apt-xapian-index-0.47ubuntu9/tests/dbus-update-apt-xapian-index.py
+===================================================================
+--- apt-xapian-index-0.47ubuntu9.orig/tests/dbus-update-apt-xapian-index.py
++++ apt-xapian-index-0.47ubuntu9/tests/dbus-update-apt-xapian-index.py
+@@ -4,7 +4,10 @@ from __future__ import print_function
+ 
+ import dbus
+ import os
+-import glib
++try:
++	from gi.repository import GLib as glib
++except ImportError:
++	import glib
+ import dbus.mainloop.glib
+ dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
+ 
diff -pruN 0.51/debian/patches/series 0.51ubuntu1/debian/patches/series
--- 0.51/debian/patches/series	1970-01-01 00:00:00.000000000 +0000
+++ 0.51ubuntu1/debian/patches/series	2020-03-27 10:49:26.000000000 +0000
@@ -0,0 +1,4 @@
+01_axi_cjk_support.patch
+02_axi-pkgname-mangled-term.patch
+06_32bit_sizes.patch
+07_glib_import.patch
diff -pruN 0.51/debian/postinst 0.51ubuntu1/debian/postinst
--- 0.51/debian/postinst	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/debian/postinst	2020-03-08 15:15:54.000000000 +0000
@@ -13,7 +13,7 @@ else
 	IONICE=""
 fi
 
-dpkg-maintscript-helper rm_conffile /etc/dbus-1/system.d/org.debian.AptXapianIndex.conf 0.46 apt-xapian-index -- "$@"
+dpkg-maintscript-helper rm_conffile /etc/dbus-1/system.d/org.debian.AptXapianIndex.conf 0.49ubuntu1~ apt-xapian-index -- "$@"
 dpkg-maintscript-helper rm_conffile /etc/bash_completion.d/axi-cache 0.47+nmu2~ apt-xapian-index -- "$@"
 
 case "$1" in
diff -pruN 0.51/debian/postrm 0.51ubuntu1/debian/postrm
--- 0.51/debian/postrm	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/debian/postrm	2020-03-08 15:15:54.000000000 +0000
@@ -2,7 +2,7 @@
 
 set -e
 
-dpkg-maintscript-helper rm_conffile /etc/dbus-1/system.d/org.debian.AptXapianIndex.conf 0.46 apt-xapian-index -- "$@"
+dpkg-maintscript-helper rm_conffile /etc/dbus-1/system.d/org.debian.AptXapianIndex.conf 0.49ubuntu1~ apt-xapian-index -- "$@"
 dpkg-maintscript-helper rm_conffile /etc/bash_completion.d/axi-cache 0.47+nmu2~ apt-xapian-index -- "$@"
 
 if [ "$1" = "remove" -o "$1" = "purge" ]; then
diff -pruN 0.51/debian/preinst 0.51ubuntu1/debian/preinst
--- 0.51/debian/preinst	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/debian/preinst	2020-03-08 15:15:54.000000000 +0000
@@ -2,7 +2,7 @@
 
 #DEBHELPER#
 
-dpkg-maintscript-helper rm_conffile /etc/dbus-1/system.d/org.debian.AptXapianIndex.conf 0.46 apt-xapian-index -- "$@"
+dpkg-maintscript-helper rm_conffile /etc/dbus-1/system.d/org.debian.AptXapianIndex.conf 0.49ubuntu1~ apt-xapian-index -- "$@"
 dpkg-maintscript-helper rm_conffile /etc/bash_completion.d/axi-cache 0.47+nmu2~ apt-xapian-index -- "$@"
 
 exit 0
diff -pruN 0.51/debian/rules 0.51ubuntu1/debian/rules
--- 0.51/debian/rules	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/debian/rules	2020-03-27 10:48:30.000000000 +0000
@@ -5,7 +5,7 @@ RELEASE_PACKAGE=apt-xapian-index
 PFX=$(CURDIR)/debian/apt-xapian-index
 
 %:
-	dh $@ --with=python3 --buildsystem=pybuild
+	dh $@ --with=python3,quilt --buildsystem=pybuild
 
 override_dh_auto_build:
 	dh_auto_build
diff -pruN 0.51/plugins/app-install.py 0.51ubuntu1/plugins/app-install.py
--- 0.51/plugins/app-install.py	2020-03-08 12:19:12.000000000 +0000
+++ 0.51ubuntu1/plugins/app-install.py	2020-03-27 10:48:33.000000000 +0000
@@ -88,8 +88,11 @@ class AppInstall(object):
         maxts = 0
         for f in os.listdir(APPINSTALLDIR):
             if f[0] == '.' or not f.endswith(".desktop"): continue
-            ts = os.path.getmtime(os.path.join(APPINSTALLDIR, f))
-            if ts > maxts: maxts = ts
+            try:
+                ts = os.path.getmtime(os.path.join(APPINSTALLDIR, f))
+                if ts > maxts: maxts = ts
+            except OSError: # ignore file not found #752195 (potential race)
+                pass
         return dict(
                 timestamp = maxts,
                 values = [
