@@ -780,13 +780,37 @@ async def _cat_file(self, path, start=None, end=None, **kwargs):
780780 size = - 1 if end is None else end - f .tell ()
781781 return f .read (size )
782782
783+ def _local_paths_for_ranges (self , paths ):
784+ """Cache file for each of paths, and which remote files to download
785+
786+ A path given more than once is downloaded once, and every occurrence
787+ reads from the same cache file.
788+ """
789+ lpaths = []
790+ local = {}
791+ download = []
792+ rpaths = []
793+ for p in paths :
794+ if p not in local :
795+ detail = self ._check_file (p )
796+ if not detail :
797+ fn = os .path .join (self .storage [- 1 ], self ._mapper (p ))
798+ download .append (fn )
799+ rpaths .append (p )
800+ else :
801+ # filecache returns (detail, fn), simplecache just fn
802+ fn = detail [1 ] if isinstance (detail , tuple ) else detail
803+ local [p ] = fn
804+ lpaths .append (local [p ])
805+ return lpaths , rpaths , download
806+
783807 async def _cat_ranges (
784808 self , paths , starts , ends , max_gap = None , on_error = "return" , ** kwargs
785809 ):
786810 logger .debug ("async cat ranges %s" , paths )
787811 lpaths , rpaths , download = self ._local_paths_for_ranges (paths )
788812 if download :
789- await self .fs ._get (rpaths , download , on_error = on_error )
813+ await self .fs ._get (rpaths , download )
790814
791815 return LocalFileSystem ().cat_ranges (
792816 lpaths , starts , ends , max_gap = max_gap , on_error = on_error , ** kwargs
@@ -902,32 +926,11 @@ def cat_ranges(
902926 logger .debug ("cat ranges %s" , paths )
903927 lpaths , rpaths , download = self ._local_paths_for_ranges (paths )
904928 if download :
905- self .fs .get (rpaths , download , on_error = on_error )
929+ self .fs .get (rpaths , download )
906930 return LocalFileSystem ().cat_ranges (
907931 lpaths , starts , ends , max_gap = max_gap , on_error = on_error , ** kwargs
908932 )
909933
910- def _local_paths_for_ranges (self , paths ):
911- """Cache file for each of paths, and which remote files to download
912-
913- A path given more than once is downloaded once, and every occurrence
914- reads from the same cache file.
915- """
916- lpaths = []
917- local = {}
918- download = []
919- rpaths = []
920- for p in paths :
921- if p not in local :
922- fn = self ._check_file (p )
923- if fn is None :
924- fn = os .path .join (self .storage [- 1 ], self ._mapper (p ))
925- download .append (fn )
926- rpaths .append (p )
927- local [p ] = fn
928- lpaths .append (local [p ])
929- return lpaths , rpaths , download
930-
931934 def _get_cached_file_before_open (self , path , ** kwargs ):
932935 sha = self ._mapper (path )
933936 fn = os .path .join (self .storage [- 1 ], sha )
0 commit comments