44from abc import ABC , abstractmethod
55from collections import defaultdict
66from collections .abc import Iterator , MutableMapping
7- from typing import TYPE_CHECKING , Any , Callable , Optional , cast
7+ from itertools import repeat
8+ from typing import TYPE_CHECKING , Any , Callable , Optional , Union , cast
89
910import attrs
1011from fsspec import Callback
1718from dvc_data .hashfile .tree import Tree
1819
1920if TYPE_CHECKING :
21+ from collections .abc import Iterable
22+
2023 from dvc_objects .fs .base import FileSystem
2124
2225 from dvc_data .hashfile .db import HashFileDB
@@ -240,7 +243,7 @@ def exists(self, entry: "DataIndexEntry", refresh: bool = False) -> bool:
240243 finally :
241244 self .index .commit ()
242245
243- def bulk_exists ( # noqa: C901
246+ def bulk_exists ( # noqa: C901, PLR0912
244247 self ,
245248 entries : list ["DataIndexEntry" ],
246249 refresh : bool = False ,
@@ -274,17 +277,24 @@ def bulk_exists( # noqa: C901
274277 _ , path = self .get (entry )
275278 path_to_entries [path ].append (entry )
276279
280+ info_results : Union [
281+ Iterable [Union [Exception , Optional [dict [str , Any ]]]], None
282+ ] = None
277283 try :
278284 self .fs .ls (self .odb .path ) # check for fs access
279- except FileNotFoundError :
285+ except FileNotFoundError as exc :
286+ info_results = repeat (exc , len (path_to_entries ))
287+ callback .relative_update (len (entries_with_hash ))
288+ except NotImplementedError :
289+ # some filesystems don't implement ls
280290 pass
281-
282- info_results = self .fs .info (
283- list (path_to_entries ),
284- batch_size = jobs ,
285- return_exceptions = True ,
286- callback = callback ,
287- )
291+ if info_results is None :
292+ info_results = self .fs .info (
293+ list (path_to_entries ),
294+ batch_size = jobs ,
295+ return_exceptions = True ,
296+ callback = callback ,
297+ )
288298
289299 for (path , _entries ), info in zip (path_to_entries .items (), info_results ):
290300 if isinstance (info , Exception ) and not isinstance (info , FileNotFoundError ):
@@ -302,6 +312,7 @@ def bulk_exists( # noqa: C901
302312 results .update (dict .fromkeys (_entries , exists ))
303313
304314 if self .index is not None :
315+ logger .debug ("Committing index results" )
305316 self .index .commit ()
306317
307318 return results
0 commit comments