Skip to content

Commit

Permalink
Verify SHA before cache write
Browse files Browse the repository at this point in the history
Co-Authored-By: Joost VandeVondele <[email protected]>
  • Loading branch information
Viren6 and vondele committed Aug 16, 2024
1 parent 5b7a67b commit 1e87a8c
Show file tree
Hide file tree
Showing 4 changed files with 12 additions and 5 deletions.
2 changes: 1 addition & 1 deletion server/montytest/api.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@
according to the route/URL mapping defined in `__init__.py`.
"""

WORKER_VERSION = 10
WORKER_VERSION = 11


@exception_view_config(HTTPException)
Expand Down
11 changes: 9 additions & 2 deletions worker/games.py
Original file line number Diff line number Diff line change
Expand Up @@ -325,7 +325,9 @@ def download_net(remote, testing_dir, net, global_cache):
url = remote + "/api/nn/" + net
print("Downloading {}".format(net))
content = requests_get(url, allow_redirects=True, timeout=HTTP_TIMEOUT).content
cache_write(global_cache, net, content)
hash = hashlib.sha256(content).hexdigest()
if hash[:12] == net[3:15]:
cache_write(global_cache, net, content)
else:
print("Using {} from global cache".format(net))

Expand Down Expand Up @@ -509,11 +511,16 @@ def setup_engine(
item_url = github_api(repo_url) + "/zipball/" + sha
print("Downloading {}".format(item_url))
blob = requests_get(item_url).content
cache_write(global_cache, sha + ".zip", blob)
blob_needs_write = True
else:
blob_needs_write = False
print("Using {} from global cache".format(sha + ".zip"))

file_list = unzip(blob, tmp_dir)
# once unzipped without error we can write as needed
if blob_needs_write:
cache_write(global_cache, sha + ".zip", blob)

prefix = os.path.commonprefix([n.filename for n in file_list])
os.chdir(tmp_dir / prefix)

Expand Down
2 changes: 1 addition & 1 deletion worker/sri.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"__version": 10, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "jJwMRIZ3A/jwtMlDYAxUDtVRK1oEmcHXCVH3Fgv+06XIUNjPzs55EFRNTD7Z/4/W", "games.py": "SIb27gdQviYwb9I4NQeaA4a3qFDbUjrIKeWqKXbcVoQCjzC/y3QhlQ5vSUXVqBzu"}
{"__version": 11, "updater.py": "gSJX/HbsPwsZnUZaFbAgF0zwWPWXv+LEw9jBhJkxFOrCH9CZS0+4U4nE2fJdeNze", "worker.py": "5H/vhWvrKp34ehp12ppQWXr0lYOQT1lHs8qjHg2XX02oLHZtMkO9iyK1IgVCwVqa", "games.py": "SOlAX95oLMYwCKNm/XkK5Uf1WPw1PGeIPzvgZqZ04AHNF2+MQ1vc+blTGu5F0JUZ"}
2 changes: 1 addition & 1 deletion worker/worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@
MIN_CARGO_MAJOR = 1
MIN_CARGO_MINOR = 77

WORKER_VERSION = 10
WORKER_VERSION = 11
FILE_LIST = ["updater.py", "worker.py", "games.py"]
HTTP_TIMEOUT = 30.0
INITIAL_RETRY_TIME = 15.0
Expand Down

0 comments on commit 1e87a8c

Please sign in to comment.