|
39 | 39 |
|
40 | 40 | from google.cloud.storage._media.requests.upload import XMLMPUContainer |
41 | 41 | from google.cloud.storage._media.requests.upload import XMLMPUPart |
42 | | -from google.cloud.storage.exceptions import DataCorruption, InvalidPathError |
| 42 | +from google.cloud.storage.exceptions import DataCorruption |
43 | 43 |
|
44 | 44 | TM_DEFAULT_CHUNK_SIZE = 32 * 1024 * 1024 |
45 | 45 | DEFAULT_MAX_WORKERS = 8 |
@@ -263,8 +263,6 @@ def upload_many( |
263 | 263 |
|
264 | 264 |
|
265 | 265 | def _resolve_path(target_dir, blob_path): |
266 | | - if os.name == "nt" and ":" in blob_path: |
267 | | - raise InvalidPathError(f"{blob_path} cannot be downloaded into {target_dir}") |
268 | 266 | target_dir = Path(target_dir) |
269 | 267 | blob_path = Path(blob_path) |
270 | 268 | # blob_path.anchor will be '/' if `blob_path` is full path else it'll empty. |
@@ -807,65 +805,43 @@ def download_many_to_path( |
807 | 805 |
|
808 | 806 | :raises: :exc:`concurrent.futures.TimeoutError` if deadline is exceeded. |
809 | 807 |
|
810 | | - :rtype: List[None|Exception|UserWarning] |
| 808 | + :rtype: list |
811 | 809 | :returns: A list of results corresponding to, in order, each item in the |
812 | | - input list. If an exception was received or a download was skipped |
813 | | - (e.g., due to existing file or path traversal), it will be the result |
814 | | - for that operation (as an Exception or UserWarning, respectively). |
815 | | - Otherwise, the result will be None for a successful download. |
| 810 | + input list. If an exception was received, it will be the result |
| 811 | + for that operation. Otherwise, the return value from the successful |
| 812 | + download method is used (which will be None). |
816 | 813 | """ |
817 | | - results = [None] * len(blob_names) |
818 | 814 | blob_file_pairs = [] |
819 | | - indices_to_process = [] |
820 | 815 |
|
821 | | - for i, blob_name in enumerate(blob_names): |
| 816 | + for blob_name in blob_names: |
822 | 817 | full_blob_name = blob_name_prefix + blob_name |
823 | | - try: |
824 | | - resolved_path = _resolve_path(destination_directory, blob_name) |
825 | | - except InvalidPathError as e: |
826 | | - msg = f"The blob {blob_name} will **NOT** be downloaded. {e}" |
827 | | - warnings.warn(msg) |
828 | | - results[i] = UserWarning(msg) |
829 | | - continue |
| 818 | + resolved_path = _resolve_path(destination_directory, blob_name) |
830 | 819 | if not resolved_path.parent.is_relative_to( |
831 | 820 | Path(destination_directory).resolve() |
832 | 821 | ): |
833 | | - msg = ( |
| 822 | + warnings.warn( |
834 | 823 | f"The blob {blob_name} will **NOT** be downloaded. " |
835 | 824 | f"The resolved destination_directory - {resolved_path.parent} - is either invalid or " |
836 | 825 | f"escapes user provided {Path(destination_directory).resolve()} . Please download this file separately using `download_to_filename`" |
837 | 826 | ) |
838 | | - warnings.warn(msg) |
839 | | - results[i] = UserWarning(msg) |
840 | 827 | continue |
841 | 828 |
|
842 | 829 | resolved_path = str(resolved_path) |
843 | | - if skip_if_exists and os.path.isfile(resolved_path): |
844 | | - msg = f"The blob {blob_name} is skipped because destination file already exists" |
845 | | - results[i] = UserWarning(msg) |
846 | | - continue |
847 | | - |
848 | 830 | if create_directories: |
849 | 831 | directory, _ = os.path.split(resolved_path) |
850 | 832 | os.makedirs(directory, exist_ok=True) |
851 | 833 | blob_file_pairs.append((bucket.blob(full_blob_name), resolved_path)) |
852 | | - indices_to_process.append(i) |
853 | 834 |
|
854 | | - many_results = download_many( |
| 835 | + return download_many( |
855 | 836 | blob_file_pairs, |
856 | 837 | download_kwargs=download_kwargs, |
857 | 838 | deadline=deadline, |
858 | 839 | raise_exception=raise_exception, |
859 | 840 | worker_type=worker_type, |
860 | 841 | max_workers=max_workers, |
861 | | - skip_if_exists=False, # skip_if_exists is handled in the loop above |
| 842 | + skip_if_exists=skip_if_exists, |
862 | 843 | ) |
863 | 844 |
|
864 | | - for meta_index, result in zip(indices_to_process, many_results): |
865 | | - results[meta_index] = result |
866 | | - |
867 | | - return results |
868 | | - |
869 | 845 |
|
870 | 846 | def download_chunks_concurrently( |
871 | 847 | blob, |
|
0 commit comments