From 1814da42b0759b1d7af89f804499fb63d283152e Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 20 Jun 2010 16:36:27 +0100 Subject: [PATCH] Removed the on-disk apt-cache cache apt-cache queries no only happen when selection fails, so they're no longer speed critical. --- zeroinstall/injector/distro.py | 66 ++++++++++++++++++++---------------------- zeroinstall/injector/fetch.py | 3 +- zeroinstall/injector/policy.py | 8 +++++ 3 files changed, 41 insertions(+), 36 deletions(-) diff --git a/zeroinstall/injector/distro.py b/zeroinstall/injector/distro.py index 4578ada..6039a01 100644 --- a/zeroinstall/injector/distro.py +++ b/zeroinstall/injector/distro.py @@ -320,7 +320,7 @@ class DebianDistribution(Distribution): def __init__(self, dpkg_status, pkgcache): self.dpkg_cache = Cache('dpkg-status.cache', dpkg_status, 2) - self.apt_cache = Cache('apt-cache-cache', pkgcache, 3) + self.apt_cache = {} def _query_installed_package(self, package): null = os.open('/dev/null', os.O_WRONLY) @@ -356,9 +356,9 @@ class DebianDistribution(Distribution): else: installed_version = None - cached = self.apt_cache.get(package) - if cached not in (None, '-'): - candidate_version, candidate_arch, candidate_size = cached.split('\t') + cached = self.apt_cache.get(package, None) + if cached: + candidate_version, candidate_arch, candidate_size = cached if candidate_version and candidate_version != installed_version: impl = factory('package:deb:%s:%s' % (package, candidate_version)) impl.version = model.parse_version(candidate_version) @@ -394,36 +394,34 @@ class DebianDistribution(Distribution): for package in package_names: # Check to see whether we could get a newer version using apt-get - cached = self.apt_cache.get(package) - if cached is None: - try: - null = os.open('/dev/null', os.O_WRONLY) - child = subprocess.Popen(['apt-cache', 'show', '--no-all-versions', '--', package], stdout = subprocess.PIPE, stderr = null) - os.close(null) - - arch = version = size = None - for line in child.stdout: - line = line.strip() - if line.startswith('Version: '): - version = line[9:] - if ':' in version: - # Debian's 'epoch' system - version = version.split(':', 1)[1] - version = try_cleanup_distro_version(version) - elif line.startswith('Architecture: '): - arch = canonical_machine(line[14:].strip()) - elif line.startswith('Size: '): - size = int(line[6:].strip()) - if version and arch: - cached = '%s\t%s\t%d' % (version, arch, size) - else: - cached = '-' - child.wait() - except Exception, ex: - warn("'apt-cache show %s' failed: %s", package, ex) - cached = '-' - # (multi-arch support? can there be multiple candidates?) - self.apt_cache.put(package, cached) + try: + null = os.open('/dev/null', os.O_WRONLY) + child = subprocess.Popen(['apt-cache', 'show', '--no-all-versions', '--', package], stdout = subprocess.PIPE, stderr = null) + os.close(null) + + arch = version = size = None + for line in child.stdout: + line = line.strip() + if line.startswith('Version: '): + version = line[9:] + if ':' in version: + # Debian's 'epoch' system + version = version.split(':', 1)[1] + version = try_cleanup_distro_version(version) + elif line.startswith('Architecture: '): + arch = canonical_machine(line[14:].strip()) + elif line.startswith('Size: '): + size = int(line[6:].strip()) + if version and arch: + cached = (version, arch, size) + else: + cached = None + child.wait() + except Exception, ex: + warn("'apt-cache show %s' failed: %s", package, ex) + cached = None + # (multi-arch support? can there be multiple candidates?) + self.apt_cache[package] = cached class RPMDistribution(CachedDistribution): """An RPM-based distribution.""" diff --git a/zeroinstall/injector/fetch.py b/zeroinstall/injector/fetch.py index d7f33f6..e651296 100644 --- a/zeroinstall/injector/fetch.py +++ b/zeroinstall/injector/fetch.py @@ -167,8 +167,7 @@ class Fetcher(object): tasks.check(fetch) # Force feed to be regenerated with the new information - if feed_url in iface_cache._feeds: - del iface_cache._feeds[feed_url] + iface_cache.get_feed(feed_url, force = True) def download_and_import_feed(self, feed_url, iface_cache, force = False): """Download the feed, download any required keys, confirm trust if needed and import. diff --git a/zeroinstall/injector/policy.py b/zeroinstall/injector/policy.py index cbd3b4b..3f0c0a6 100644 --- a/zeroinstall/injector/policy.py +++ b/zeroinstall/injector/policy.py @@ -362,6 +362,14 @@ class Policy(object): del downloads_in_progress[f] downloads_finished.add(f) + # Need to refetch any "distribution" feed that + # depends on this one + distro_feed_url = 'distribution:' + f + if distro_feed_url in downloads_finished: + downloads_finished.remove(distro_feed_url) + if distro_feed_url in downloads_in_progress: + del downloads_in_progress[distro_feed_url] + @tasks.async def solve_and_download_impls(self, refresh = False, select_only = False): """Run L{solve_with_downloads} and then get the selected implementations too. -- 2.11.4.GIT