From 0a34541c5938d656434bcb59495de6b9887e8359 Mon Sep 17 00:00:00 2001 From: ppigazzini Date: Wed, 8 Jan 2025 12:25:01 +0100 Subject: [PATCH] Delete file from cache --- worker/games.py | 28 ++++++++++++++++++---------- worker/sri.txt | 2 +- 2 files changed, 19 insertions(+), 11 deletions(-) diff --git a/worker/games.py b/worker/games.py index 2b1906718..5373bee72 100644 --- a/worker/games.py +++ b/worker/games.py @@ -170,6 +170,17 @@ def cache_write(cache, name, data): return +def cache_remove(cache, name): + """Remove a file from the global cache on disk""" + if cache == "": + return + + try: + (Path(cache) / name).unlink() + except Exception as e: + return + + # See https://stackoverflow.com/questions/16511337/correct-way-to-try-except-using-python-requests-module # for background. # It may be useful to introduce more refined http exception handling in the future. @@ -333,7 +344,8 @@ def fetch_validated_net(remote, testing_dir, net, global_cache): cache_write(global_cache, net, content) else: if not is_valid_net(content, net): - print(f"{net} from global cache is invalid") + print(f"{net} from global cache is invalid, removing") + cache_remove(global_cache, net) return False print(f"Using {net} from global cache") @@ -354,18 +366,15 @@ def validate_net(testing_dir, net): def establish_validated_net(remote, testing_dir, net, global_cache): if (testing_dir / net).exists() and validate_net(testing_dir, net): return - - attempts = 5 - attempt = 0 + + attempt, attempts = 0, 5 while True: attempt += 1 try: if fetch_validated_net(remote, testing_dir, net, global_cache): return else: - raise WorkerException( - "Failed to validate the network: {}".format(net) - ) + raise WorkerException(f"Failed to validate the network: {net}") except FatalException: raise except WorkerException: @@ -373,9 +382,8 @@ def establish_validated_net(remote, testing_dir, net, global_cache): raise waitTime = UPDATE_RETRY_TIME * attempt print( - "Failed to download {} in attempt {}, trying in {} seconds.".format( - net, attempt, waitTime - ) + f"Failed to fetch {net} in attempt {attempt},", + f"trying in {waitTime} seconds" ) time.sleep(waitTime) diff --git a/worker/sri.txt b/worker/sri.txt index 4a9d7b87e..e05047604 100644 --- a/worker/sri.txt +++ b/worker/sri.txt @@ -1 +1 @@ -{"__version": 246, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "NW2mz+hDNprnOcMpw6k8rGUEXE4QvZwkWPma8kYg0uswQ7gQ+OIXBDFK7Fhz/Brt", "games.py": "757WYTqKEY65A7BbUM5+CHIUDVHZn0rJRH0pNsf1gghGG5+nKxkA8zw0riGZCXgu"} +{"__version": 246, "updater.py": "Mg+pWOgGA0gSo2TuXuuLCWLzwGwH91rsW1W3ixg3jYauHQpRMtNdGnCfuD1GqOhV", "worker.py": "NW2mz+hDNprnOcMpw6k8rGUEXE4QvZwkWPma8kYg0uswQ7gQ+OIXBDFK7Fhz/Brt", "games.py": "/MyBz+2JVyL/fEq4YLlHGPfr4ayk5avNwxSQVn0kuqeJMgN6HqfJngaFJ4TPSbOu"}