GitHub issue #5295: Extractions failed when .zip file located on read-only path (e.g., SageMaker FastFile mode)
State: closed | Created: 2022-11-25T03:59:43Z

### Describe the bug

Hi,

`load_dataset()` does not work .zip files located on a read-only directory. Looks like it's because Dataset creates a lock file in the [same directory](https://github.com/huggingface/datasets/blob/df4bdd365f2abb695f113cbf8856a925bc70901b/src/datasets/utils/extract.py)  as the .zip file.

Encountered this when attempting `load_dataset()` on a datadir with SageMaker FastFile mode.

### Steps to reproduce the bug

```python
# Showing relevant lines only.

hyperparameters = {
    "dataset_name": "ydshieh/coco_dataset_script",
    "dataset_config_name": 2017,
    "data_dir": "/opt/ml/input/data/coco",
    "cache_dir": "/tmp/huggingface-cache",  # Fix dataset complains out-of-space.
    ...
}

estimator = PyTorch(
    base_job_name="clip",
    source_dir="../src/sm-entrypoint",
    entry_point="run_clip.py",  # Transformers/src/examples/pytorch/contrastive-image-text/run_clip.py
    framework_version="1.12",
    py_version="py38",
    hyperparameters=hyperparameters,
    instance_count=1,
    instance_type="ml.p3.16xlarge",
    volume_size=100,
    distribution={"smdistributed": {"dataparallel": {"enabled": True}}},
)

fast_file = lambda x: TrainingInput(x, input_mode='FastFile') 
estimator.fit(
    {
        "pre-trained": fast_file("s3://vm-sagemakerr-us-east-1/clip/pre-trained-checkpoint/"),
        "coco": fast_file("s3://vm-sagemakerr-us-east-1/clip/coco-zip-files/"),
    }
)
```

Error message:

```text
ErrorMessage "OSError: [Errno 30] Read-only file system: '/opt/ml/input/data/coco/image_info_test2017.zip.lock'
 """
 
 The above exception was the direct cause of the following exception
 Traceback (most recent call last)
 File "/opt/conda/lib/python3.8/runpy.py", line 194, in _run_module_as_main
 return _run_code(code, main_globals, None,
 File "/opt/conda/lib/python3.8/runpy.py", line 87, in _run_code
 exec(code, run_globals)
 File "/opt/conda/lib/python3.8/site-packages/mpi4py/__main__.py", line 7, in <module>
 main()
 File "/opt/conda/lib/python3.8/site-packages/mpi4py/run.py", line 198, in main
 run_command_line(args)
 File "/opt/conda/lib/python3.8/site-packages/mpi4py/run.py", line 47, in run_command_line
 run_path(sys.argv[0], run_name='__main__')
 File "/opt/conda/lib/python3.8/runpy.py", line 265, in run_path
 return _run_module_code(code, init_globals, run_name,
 File "/opt/conda/lib/python3.8/runpy.py", line 97, in _run_module_code
 _run_code(code, mod_globals, init_globals,
 File "run_clip_smddp.py", line 594, in <module>
 File "run_clip_smddp.py", line 327, in main
 dataset = load_dataset(
 File "/opt/conda/lib/python3.8/site-packages/datasets/load.py", line 1741, in load_dataset
 builder_instance.download_and_prepare(
 File "/opt/conda/lib/python3.8/site-packages/datasets/builder.py", line 822, in download_and_prepare
 self._download_and_prepare(
 File "/opt/conda/lib/python3.8/site-packages/datasets/builder.py", line 1555, in _download_and_prepare
 super()._download_and_prepare(
 File "/opt/conda/lib/python3.8/site-packages/datasets/builder.py", line 891, in _download_and_prepare
 split_generators = self._split_generators(dl_manager, **split_generators_kwargs)
 File "/root/.cache/huggingface/modules/datasets_modules/datasets/ydshieh--coco_dataset_script/e033205c0266a54c10be132f9264f2a39dcf893e798f6756d224b1ff5078998f/coco_dataset_script.py", line 123, in _split_generators
 archive_path = dl_manager.download_and_extract(_DL_URLS)
 File "/opt/conda/lib/python3.8/site-packages/datasets/download/download_manager.py", line 447, in download_and_extract
 return self.extract(self.download(url_or_urls))
 File "/opt/conda/lib/python3.8/site-packages/datasets/download/download_manager.py", line 419, in extract
 extracted_paths = map_nested(
 File "/opt/conda/lib/python3.8/site-packages/datasets/utils/py_utils.py", line 472, in map_nested
 mapped = pool.map(_single_map_nested, split_kwds)
 File "/opt/conda/lib/python3.8/multiprocessing/pool.py", line 364, in map
 return self._map_async(func, iterable, mapstar, chunksize).get()
 File "/opt/conda/lib/python3.8/multiprocessing/pool.py", line 771, in get
 raise self._value
 OSError: [Errno 30] Read-only file system: '/opt/ml/input/data/coco/image_info_test2017.zip.lock'"

```

### Expected behavior

`load_dataset()` to succeed, just like when .zip file is passed in SageMaker File mode.

### Environment info

* datasets-2.7.1
* transformers-4.24.0
* python-3.8
* torch-1.12
* SageMaker PyTorch DLC