Skip to content

Commit

Permalink
Check if file exists before sending the GET request
Browse files Browse the repository at this point in the history
  • Loading branch information
kcosta42 committed Jan 4, 2022
1 parent 9cc8e56 commit b6f17cb
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 b6f17cb

Please sign in to comment.