@@ -357,7 +357,7 @@ async def root_join(*parts: str) -> str:
357357
358358
359359async def exists (path : str ) -> bool :
360- fs = await filesystem ( )
360+ fs , _ = _get_fs_for_path ( path )
361361 try :
362362 return await asyncio .to_thread (fs .exists , path )
363363 finally :
@@ -368,7 +368,8 @@ async def exists(path: str) -> bool:
368368async def isdir (path : str , fs = None ) -> bool :
369369 filesys = fs
370370 try :
371- filesys = fs if fs is not None else await filesystem ()
371+ if fs is None :
372+ filesys , _ = _get_fs_for_path (path )
372373 return await asyncio .to_thread (filesys .isdir , path )
373374 except Exception :
374375 return False
@@ -381,7 +382,7 @@ async def isdir(path: str, fs=None) -> bool:
381382async def isfile (path : str ) -> bool :
382383 fs = None
383384 try :
384- fs = await filesystem ( )
385+ fs , _ = _get_fs_for_path ( path )
385386 return await asyncio .to_thread (fs .isfile , path )
386387 except Exception :
387388 return False
@@ -391,7 +392,7 @@ async def isfile(path: str) -> bool:
391392
392393
393394async def makedirs (path : str , exist_ok : bool = True ) -> None :
394- fs = await filesystem ( )
395+ fs , _ = _get_fs_for_path ( path )
395396 try :
396397 await asyncio .to_thread (fs .makedirs , path , exist_ok = exist_ok )
397398 except TypeError :
@@ -404,8 +405,12 @@ async def makedirs(path: str, exist_ok: bool = True) -> None:
404405
405406
406407async def ls (path : str , detail : bool = False , fs = None ):
407- # Use provided filesystem or get default
408- filesys = fs if fs is not None else await filesystem ()
408+ # Use provided filesystem or pick one based on the path's scheme so that
409+ # local paths don't get routed through a configured remote filesystem.
410+ if fs is not None :
411+ filesys = fs
412+ else :
413+ filesys , _ = _get_fs_for_path (path )
409414 try :
410415 paths = await asyncio .to_thread (filesys .ls , path , detail = detail )
411416 is_remote = path .startswith (_REMOTE_PATH_PREFIXES )
0 commit comments