|
19 | 19 | import xml.dom.minidom
|
20 | 20 | import zipfile
|
21 | 21 | from collections.abc import Generator
|
22 |
| -from contextlib import contextmanager |
23 | 22 | from io import BytesIO
|
24 | 23 | from itertools import chain
|
25 | 24 | from pathlib import Path, PurePosixPath
|
@@ -399,23 +398,15 @@ def get_from_cache(
|
399 | 398 |
|
400 | 399 | incomplete_path = cache_path + ".incomplete"
|
401 | 400 |
|
402 |
| - @contextmanager |
403 |
| - def temp_file_manager(mode="w+b"): |
404 |
| - with open(incomplete_path, mode) as f: |
405 |
| - yield f |
406 |
| - |
407 | 401 | # Download to temporary file, then copy to cache path once finished.
|
408 | 402 | # Otherwise, you get corrupt cache entries if the download gets interrupted.
|
409 |
| - with temp_file_manager() as temp_file: |
| 403 | + with open(incomplete_path, "w+b") as temp_file: |
410 | 404 | logger.info(f"{url} not found in cache or force_download set to True, downloading to {temp_file.name}")
|
411 | 405 | # GET file object
|
412 | 406 | fsspec_get(url, temp_file, storage_options=storage_options, desc=download_desc, disable_tqdm=disable_tqdm)
|
413 | 407 |
|
414 | 408 | logger.info(f"storing {url} in cache at {cache_path}")
|
415 | 409 | shutil.move(temp_file.name, cache_path)
|
416 |
| - umask = os.umask(0o666) |
417 |
| - os.umask(umask) |
418 |
| - os.chmod(cache_path, 0o666 & ~umask) |
419 | 410 |
|
420 | 411 | logger.info(f"creating metadata file for {cache_path}")
|
421 | 412 | meta = {"url": url, "etag": etag}
|
|
0 commit comments