Skip to content

Commit

Permalink
Merge pull request #14 from kcosta42/patch-1
Browse files Browse the repository at this point in the history
Check if file exists before sending the GET request
  • Loading branch information
unixpickle committed Mar 21, 2022
2 parents 11bf257 + b6f17cb commit 69b5307
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions glide_text2im/download.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ def fetch_file_cached(
if cache_dir is None:
cache_dir = default_cache_dir()
os.makedirs(cache_dir, exist_ok=True)
local_path = os.path.join(cache_dir, url.split("/")[-1])
if os.path.exists(local_path):
return local_path
response = requests.get(url, stream=True)
size = int(response.headers.get("content-length", "0"))
local_path = os.path.join(cache_dir, url.split("/")[-1])
with FileLock(local_path + ".lock"):
if os.path.exists(local_path):
return local_path
if progress:
pbar = tqdm(total=size, unit="iB", unit_scale=True)
tmp_path = local_path + ".tmp"
Expand Down

0 comments on commit 69b5307

Please sign in to comment.