Skip to content

Commit

Permalink
Fix OSError when downloading multiple files to the same temp dir.
Browse files Browse the repository at this point in the history
  • Loading branch information
fabiocaccamo committed Jan 2, 2023
1 parent 134f659 commit dbbe800
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
1 change: 0 additions & 1 deletion fsutil/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -407,7 +407,6 @@ def download_file(url, dirpath=None, filename=None, chunk_size=8192, **kwargs):
dirpath = _get_path(dirpath)
filename = filename or get_filename(url) or "download"
filepath = join_path(dirpath, filename)
assert_not_dir(dirpath)
make_dirs_for_file(filepath)
kwargs["stream"] = True
with requests.get(url, **kwargs) as response:
Expand Down
11 changes: 11 additions & 0 deletions tests/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -410,6 +410,17 @@ def test_download_file(self):
fsutil.remove_file(path)
self.assertFalse(fsutil.exists(path))

def test_download_file_multiple_to_temp_dir(self):
for i in range(3):
url = "https://raw.githubusercontent.com/fabiocaccamo/python-fsutil/master/README.md"
path = fsutil.download_file(url)
self.assertTrue(fsutil.exists(path))
lines = fsutil.read_file_lines(path, skip_empty=False)
lines_count = len(lines)
self.assertTrue(lines_count > 500 and lines_count < 1000)
fsutil.remove_file(path)
self.assertFalse(fsutil.exists(path))

def test_download_file_without_requests_installed(self):
requests_installed = fsutil.requests_installed
fsutil.requests_installed = False
Expand Down

0 comments on commit dbbe800

Please sign in to comment.