|
18 | 18 |
|
19 | 19 | from collections import abc |
20 | 20 | import datetime |
| 21 | +import fnmatch |
| 22 | +import inspect |
21 | 23 | import logging |
22 | 24 | import os |
23 | 25 | import secrets |
@@ -1344,12 +1346,24 @@ def read_json( |
1344 | 1346 | def _check_file_size(self, filepath: str): |
1345 | 1347 | max_size = 1024 * 1024 * 1024 # 1 GB in bytes |
1346 | 1348 | if filepath.startswith("gs://"): # GCS file path |
| 1349 | + bucket_name, blob_path = filepath.split("/", 3)[2:] |
| 1350 | + |
1347 | 1351 | client = storage.Client() |
1348 | | - bucket_name, blob_name = filepath.split("/", 3)[2:] |
1349 | 1352 | bucket = client.bucket(bucket_name) |
1350 | | - blob = bucket.blob(blob_name) |
1351 | | - blob.reload() |
1352 | | - file_size = blob.size |
| 1353 | + |
| 1354 | + list_blobs_params = inspect.signature(bucket.list_blobs).parameters |
| 1355 | + if "match_glob" in list_blobs_params: |
| 1356 | + # Modern, efficient method for new library versions |
| 1357 | + matching_blobs = bucket.list_blobs(match_glob=blob_path) |
| 1358 | + file_size = sum(blob.size for blob in matching_blobs) |
| 1359 | + else: |
| 1360 | + # Fallback method for older library versions |
| 1361 | + prefix = blob_path.split("*", 1)[0] |
| 1362 | + all_blobs = bucket.list_blobs(prefix=prefix) |
| 1363 | + matching_blobs = [ |
| 1364 | + blob for blob in all_blobs if fnmatch.fnmatch(blob.name, blob_path) |
| 1365 | + ] |
| 1366 | + file_size = sum(blob.size for blob in matching_blobs) |
1353 | 1367 | elif os.path.exists(filepath): # local file path |
1354 | 1368 | file_size = os.path.getsize(filepath) |
1355 | 1369 | else: |
|
0 commit comments