From e11ae1ad52ccce278ecff1c90ec889224423527f Mon Sep 17 00:00:00 2001 From: Thomas Leonard Date: Sun, 20 Apr 2008 21:09:20 +0100 Subject: [PATCH] Also get GPG keys using the mirror. If we got a feed from a mirror, get the key from there too. --- tests/testdownload.py | 2 +- zeroinstall/injector/fetch.py | 10 ++++++++-- zeroinstall/injector/iface_cache.py | 6 ++++-- 3 files changed, 13 insertions(+), 5 deletions(-) diff --git a/tests/testdownload.py b/tests/testdownload.py index b5ce79d..f25e794 100755 --- a/tests/testdownload.py +++ b/tests/testdownload.py @@ -223,7 +223,7 @@ class TestDownload(BaseTest): sys.stdout = StringIO() getLogger().setLevel(ERROR) trust.trust_db.trust_key('DE937DD411906ACF7C263B396FCF121BE2390E0B', 'localhost:8000') - self.child = server.handle_requests(server.Give404('/Hello.xml'), 'latest.xml', '6FCF121BE2390E0B.gpg') + self.child = server.handle_requests(server.Give404('/Hello.xml'), 'latest.xml', '/0mirror/keys/6FCF121BE2390E0B.gpg') policy = autopolicy.AutoPolicy('http://localhost:8000/Hello.xml', download_only = False) policy.fetcher.feed_mirror = 'http://localhost:8000/0mirror' diff --git a/zeroinstall/injector/fetch.py b/zeroinstall/injector/fetch.py index 98f26fb..d0d97be 100644 --- a/zeroinstall/injector/fetch.py +++ b/zeroinstall/injector/fetch.py @@ -14,7 +14,7 @@ from zeroinstall.injector.model import DownloadSource, Recipe, SafeException, ne from zeroinstall.injector.iface_cache import PendingFeed def _escape_slashes(path): - return path.replace('/', '#') + return path.replace('/', '%23') def _get_feed_dir(feed): """The algorithm from 0mirror.""" @@ -188,7 +188,13 @@ class Fetcher(object): pending = PendingFeed(feed_url, stream) iface_cache.add_pending(pending) - keys_downloaded = tasks.Task(pending.download_keys(self.handler, feed_hint = feed_url), "download keys for " + feed_url) + if using_mirror: + # If we got the feed from a mirror, get the key from there too + key_mirror = self.feed_mirror + '/keys/' + else: + key_mirror = None + + keys_downloaded = tasks.Task(pending.download_keys(self.handler, feed_hint = feed_url, key_mirror = key_mirror), "download keys for " + feed_url) yield keys_downloaded.finished tasks.check(keys_downloaded.finished) diff --git a/zeroinstall/injector/iface_cache.py b/zeroinstall/injector/iface_cache.py index 0154a2f..5b453be 100644 --- a/zeroinstall/injector/iface_cache.py +++ b/zeroinstall/injector/iface_cache.py @@ -67,12 +67,14 @@ class PendingFeed(object): self.signed_data = signed_data self.recheck() - def download_keys(self, handler, feed_hint = None): + def download_keys(self, handler, feed_hint = None, key_mirror = None): """Download any required GPG keys not already on our keyring. When all downloads are done (successful or otherwise), add any new keys to the keyring, L{recheck}. @param handler: handler to manage the download @type handler: L{handler.Handler} + @param key_mirror: URL of directory containing keys, or None to use feed's directory + @type key_mirror: str """ downloads = {} blockers = [] @@ -80,7 +82,7 @@ class PendingFeed(object): key_id = x.need_key() if key_id: import urlparse - key_url = urlparse.urljoin(self.url, '%s.gpg' % key_id) + key_url = urlparse.urljoin(key_mirror or self.url, '%s.gpg' % key_id) info("Fetching key from %s", key_url) dl = handler.get_download(key_url, hint = feed_hint) downloads[dl.downloaded] = (dl, dl.tempfile) -- 2.11.4.GIT