Skip to content

Commit

Permalink
Fix race when preparing download location
Browse files Browse the repository at this point in the history
If multiple threads start their downloads into the same directory, they can
call os.mkdirs at the same time, leading to "File exists" exceptions and
subsequent failures to download some files. Fix this by supplying an exist_ok
argument and removing the racy isdir check.
  • Loading branch information
viacheslavka committed Apr 10, 2024
1 parent 6daf70d commit d14817c
Showing 1 changed file with 1 addition and 2 deletions.
3 changes: 1 addition & 2 deletions minigalaxy/download_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -317,8 +317,7 @@ def __prepare_location(self, save_location):
"""
# Make sure the directory exists
save_directory = os.path.dirname(save_location)
if not os.path.isdir(save_directory):
os.makedirs(save_directory, mode=0o755)
os.makedirs(save_directory, mode=0o755, exist_ok=True)

# Fail if the file already exists
if os.path.isdir(save_location):
Expand Down

0 comments on commit d14817c

Please sign in to comment.