Merge pull request #2384 from dimagalat/master

Releasing file lock
This commit is contained in:
Thomas Wolf 2020-01-14 13:19:01 +01:00 committed by GitHub
commit 2b566c182e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 7 additions and 10 deletions

View File

@ -385,16 +385,13 @@ def get_from_cache(
else: else:
http_get(url, temp_file, proxies=proxies, resume_size=resume_size, user_agent=user_agent) http_get(url, temp_file, proxies=proxies, resume_size=resume_size, user_agent=user_agent)
# we are copying the file before closing it, so flush to avoid truncation logger.info("storing %s in cache at %s", url, cache_path)
temp_file.flush() os.rename(temp_file.name, cache_path)
logger.info("storing %s in cache at %s", url, cache_path) logger.info("creating metadata file for %s", cache_path)
os.rename(temp_file.name, cache_path) meta = {"url": url, "etag": etag}
meta_path = cache_path + ".json"
logger.info("creating metadata file for %s", cache_path) with open(meta_path, "w") as meta_file:
meta = {"url": url, "etag": etag} json.dump(meta, meta_file)
meta_path = cache_path + ".json"
with open(meta_path, "w") as meta_file:
json.dump(meta, meta_file)
return cache_path return cache_path