Skip to content

Commit 67907b1

Browse files
authored
Avoid global umask for setting file mode. (#7547)
* Avoid global umask for setting file mode. * Remove old code and simplify. * make style
1 parent 644fd5d commit 67907b1

File tree

1 file changed

+1
-10
lines changed

1 file changed

+1
-10
lines changed

src/datasets/utils/file_utils.py

Lines changed: 1 addition & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,6 @@
1919
import xml.dom.minidom
2020
import zipfile
2121
from collections.abc import Generator
22-
from contextlib import contextmanager
2322
from io import BytesIO
2423
from itertools import chain
2524
from pathlib import Path, PurePosixPath
@@ -399,23 +398,15 @@ def get_from_cache(
399398

400399
incomplete_path = cache_path + ".incomplete"
401400

402-
@contextmanager
403-
def temp_file_manager(mode="w+b"):
404-
with open(incomplete_path, mode) as f:
405-
yield f
406-
407401
# Download to temporary file, then copy to cache path once finished.
408402
# 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:
410404
logger.info(f"{url} not found in cache or force_download set to True, downloading to {temp_file.name}")
411405
# GET file object
412406
fsspec_get(url, temp_file, storage_options=storage_options, desc=download_desc, disable_tqdm=disable_tqdm)
413407

414408
logger.info(f"storing {url} in cache at {cache_path}")
415409
shutil.move(temp_file.name, cache_path)
416-
umask = os.umask(0o666)
417-
os.umask(umask)
418-
os.chmod(cache_path, 0o666 & ~umask)
419410

420411
logger.info(f"creating metadata file for {cache_path}")
421412
meta = {"url": url, "etag": etag}

0 commit comments

Comments
 (0)