|
53 | 53 | MAX_SINGLE_STREAM_SIZE = 1024 * 1024 * 10 # 10MB |
54 | 54 | MIN_BANDWIDTH = 0.5 * (1024 * 1024) # 0.5 MB/s |
55 | 55 |
|
| 56 | +# Timeout when performing a stat call |
| 57 | +STAT_TIMEOUT = 10 |
| 58 | + |
56 | 59 |
|
57 | 60 | @contextmanager |
58 | 61 | def setGfalSetting( |
@@ -218,11 +221,12 @@ def exists(self, path): |
218 | 221 | successful = {} |
219 | 222 | failed = {} |
220 | 223 |
|
221 | | - for url in urls: |
222 | | - try: |
223 | | - successful[url] = self.__singleExists(url) |
224 | | - except Exception as e: |
225 | | - failed[url] = repr(e) |
| 224 | + with setGfalSetting(self.ctx, "CORE", "NAMESPACE_TIMEOUT", STAT_TIMEOUT): |
| 225 | + for url in urls: |
| 226 | + try: |
| 227 | + successful[url] = self.__singleExists(url) |
| 228 | + except Exception as e: |
| 229 | + failed[url] = repr(e) |
226 | 230 |
|
227 | 231 | resDict = {"Failed": failed, "Successful": successful} |
228 | 232 | return resDict |
@@ -268,29 +272,15 @@ def isFile(self, path): |
268 | 272 | successful = {} |
269 | 273 | failed = {} |
270 | 274 |
|
271 | | - for url in urls: |
272 | | - try: |
273 | | - successful[url] = self._isSingleFile(url) |
274 | | - except Exception as e: |
275 | | - failed[url] = repr(e) |
| 275 | + with setGfalSetting(self.ctx, "CORE", "NAMESPACE_TIMEOUT", STAT_TIMEOUT): |
| 276 | + for url in urls: |
| 277 | + try: |
| 278 | + successful[url] = S_ISREG(self.ctx.stat(url).st_mode) |
| 279 | + except Exception as e: |
| 280 | + failed[url] = repr(e) |
276 | 281 |
|
277 | 282 | return {"Failed": failed, "Successful": successful} |
278 | 283 |
|
279 | | - def _isSingleFile(self, path: str) -> bool: |
280 | | - """Checking if :path: exists and is a file |
281 | | -
|
282 | | - :param str path: single path on the storage (srm://...) |
283 | | -
|
284 | | - :returns: boolean |
285 | | -
|
286 | | - :raises: |
287 | | - gfal2.GError: gfal problem |
288 | | -
|
289 | | - """ |
290 | | - |
291 | | - statInfo = self.ctx.stat(path) |
292 | | - return S_ISREG(statInfo.st_mode) |
293 | | - |
294 | 284 | @convertToReturnValue |
295 | 285 | def putFile(self, path, sourceSize: int = 0): |
296 | 286 | """Put a copy of a local file or a file on another srm storage to a directory on the |
@@ -600,7 +590,8 @@ def _getSingleFileSize(self, path: str) -> int: |
600 | 590 | log = self.log.getLocalSubLogger("GFAL2_StorageBase._getSingleFileSize") |
601 | 591 | log.debug(f"Determining file size of {path}") |
602 | 592 |
|
603 | | - statInfo = self.ctx.stat(path) # keeps info like size, mode. |
| 593 | + with setGfalSetting(self.ctx, "CORE", "NAMESPACE_TIMEOUT", STAT_TIMEOUT): |
| 594 | + statInfo = self.ctx.stat(path) # keeps info like size, mode. |
604 | 595 |
|
605 | 596 | # If it is not a file |
606 | 597 | if not S_ISREG(statInfo.st_mode): |
@@ -675,7 +666,8 @@ def _getSingleMetadata(self, path: str) -> dict[str, Any]: |
675 | 666 | log = self.log.getLocalSubLogger("GFAL2_StorageBase._getSingleMetadata") |
676 | 667 | log.debug(f"Reading metadata for {path}") |
677 | 668 |
|
678 | | - statInfo = self.ctx.stat(path) |
| 669 | + with setGfalSetting(self.ctx, "CORE", "NAMESPACE_TIMEOUT", STAT_TIMEOUT): |
| 670 | + statInfo = self.ctx.stat(path) |
679 | 671 |
|
680 | 672 | metadataDict = self.__parseStatInfoFromApiOutput(statInfo) |
681 | 673 | if metadataDict["File"] and self.checksumType: |
@@ -942,27 +934,15 @@ def isDirectory(self, path): |
942 | 934 | successful = {} |
943 | 935 | failed = {} |
944 | 936 |
|
945 | | - for url in urls: |
946 | | - try: |
947 | | - successful[url] = self._isSingleDirectory(url) |
948 | | - except Exception as e: |
949 | | - failed[url] = f"Failed to determine if path is a directory {repr(e)}" |
| 937 | + with setGfalSetting(self.ctx, "CORE", "NAMESPACE_TIMEOUT", STAT_TIMEOUT): |
| 938 | + for url in urls: |
| 939 | + try: |
| 940 | + successful[url] = S_ISDIR(self.ctx.stat(url).st_mode) |
| 941 | + except Exception as e: |
| 942 | + failed[url] = f"Failed to determine if path is a directory {repr(e)}" |
950 | 943 |
|
951 | 944 | return {"Failed": failed, "Successful": successful} |
952 | 945 |
|
953 | | - def _isSingleDirectory(self, path: str) -> bool: |
954 | | - """Checking if :path: exists and is a directory |
955 | | -
|
956 | | - :param str path: single path on the storage (srm://...) |
957 | | -
|
958 | | - :returns: boolean if it is a directory or not |
959 | | -
|
960 | | - :raises: |
961 | | - gfal2.GError in case of gfal problem |
962 | | - """ |
963 | | - |
964 | | - return S_ISDIR(self.ctx.stat(path).st_mode) |
965 | | - |
966 | 946 | @convertToReturnValue |
967 | 947 | def listDirectory(self, path): |
968 | 948 | """List the content of the path provided |
|
0 commit comments