>From 5400ba6ecbccf946aa4d5a8ddaaa2e1d7b784d3f Mon Sep 17 00:00:00 2001 From: David James <davidja...@google.com> Date: Thu, 23 Oct 2014 18:40:28 -0700 Subject: [PATCH] If a binhost file sets a TTL header, honor it.
BUG=chromium:381970 TEST=Run it locally and verify TTL headers are respected. Change-Id: I54b2afa6fefdb3de1b9a03aaa3af37fd587e1a11 Reviewed-on: https://chromium-review.googlesource.com/225279 Reviewed-by: Zac Medico <zmed...@gmail.com> Reviewed-by: Mike Frysinger <vap...@chromium.org> Commit-Queue: David James <davidja...@chromium.org> Tested-by: David James <davidja...@chromium.org> --- pym/portage/dbapi/bintree.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py index 229ce3b..e6eae33 100644 --- a/pym/portage/dbapi/bintree.py +++ b/pym/portage/dbapi/bintree.py @@ -43,6 +43,7 @@ import subprocess import sys import tempfile import textwrap +import time import traceback import warnings from gzip import GzipFile @@ -879,11 +880,16 @@ class binarytree(object): if e.errno != errno.ENOENT: raise local_timestamp = pkgindex.header.get("TIMESTAMP", None) + download_timestamp = float(pkgindex.header.get("DOWNLOAD_TIMESTAMP", 0)) remote_timestamp = None rmt_idx = self._new_pkgindex() proc = None tmp_filename = None try: + ttl = float(pkgindex.header.get("TTL", 0)) + if download_timestamp and ttl and download_timestamp + ttl > time.time(): + raise UseCachedCopyOfRemoteIndex() + # urlparse.urljoin() only works correctly with recognized # protocols and requires the base url to have a trailing # slash, so join manually... @@ -1022,6 +1028,7 @@ class binarytree(object): pass if pkgindex is rmt_idx: pkgindex.modified = False # don't update the header + pkgindex.header["DOWNLOAD_TIMESTAMP"] = str(long(time.time())) try: ensure_dirs(os.path.dirname(pkgindex_file)) f = atomic_ofstream(pkgindex_file) -- 2.0.4