Gentoo Archives: gentoo-portage-dev

From: Zac Medico <zmedico@g.o>
To: gentoo-portage-dev@l.g.o
Subject: [gentoo-portage-dev] [PATCH] If a binhost file sets a TTL header, honor it.
Date: Fri, 24 Oct 2014 19:24:55
Message-Id: 544AA783.1000307@gentoo.org
1 From 5400ba6ecbccf946aa4d5a8ddaaa2e1d7b784d3f Mon Sep 17 00:00:00 2001
2 From: David James <davidjames@××××××.com>
3 Date: Thu, 23 Oct 2014 18:40:28 -0700
4 Subject: [PATCH] If a binhost file sets a TTL header, honor it.
5
6 BUG=chromium:381970
7 TEST=Run it locally and verify TTL headers are respected.
8
9 Change-Id: I54b2afa6fefdb3de1b9a03aaa3af37fd587e1a11
10 Reviewed-on: https://chromium-review.googlesource.com/225279
11 Reviewed-by: Zac Medico <zmedico@×××××.com>
12 Reviewed-by: Mike Frysinger <vapier@××××××××.org>
13 Commit-Queue: David James <davidjames@××××××××.org>
14 Tested-by: David James <davidjames@××××××××.org>
15 ---
16 pym/portage/dbapi/bintree.py | 7 +++++++
17 1 file changed, 7 insertions(+)
18
19 diff --git a/pym/portage/dbapi/bintree.py b/pym/portage/dbapi/bintree.py
20 index 229ce3b..e6eae33 100644
21 --- a/pym/portage/dbapi/bintree.py
22 +++ b/pym/portage/dbapi/bintree.py
23 @@ -43,6 +43,7 @@ import subprocess
24 import sys
25 import tempfile
26 import textwrap
27 +import time
28 import traceback
29 import warnings
30 from gzip import GzipFile
31 @@ -879,11 +880,16 @@ class binarytree(object):
32 if e.errno != errno.ENOENT:
33 raise
34 local_timestamp = pkgindex.header.get("TIMESTAMP", None)
35 + download_timestamp = float(pkgindex.header.get("DOWNLOAD_TIMESTAMP", 0))
36 remote_timestamp = None
37 rmt_idx = self._new_pkgindex()
38 proc = None
39 tmp_filename = None
40 try:
41 + ttl = float(pkgindex.header.get("TTL", 0))
42 + if download_timestamp and ttl and download_timestamp + ttl > time.time():
43 + raise UseCachedCopyOfRemoteIndex()
44 +
45 # urlparse.urljoin() only works correctly with recognized
46 # protocols and requires the base url to have a trailing
47 # slash, so join manually...
48 @@ -1022,6 +1028,7 @@ class binarytree(object):
49 pass
50 if pkgindex is rmt_idx:
51 pkgindex.modified = False # don't update the header
52 + pkgindex.header["DOWNLOAD_TIMESTAMP"] = str(long(time.time()))
53 try:
54 ensure_dirs(os.path.dirname(pkgindex_file))
55 f = atomic_ofstream(pkgindex_file)
56 --
57 2.0.4

Replies