From 70dc136bc6a638d169afb3ebb3e48576adb49313 Mon Sep 17 00:00:00 2001 From: Andre Lobato Date: Mon, 9 Dec 2024 11:19:57 +1300 Subject: [PATCH] Pass listing kwargs to storage.ls --- oceanum/storage/filesystem.py | 31 +++++++++++++++++++++++++++---- 1 file changed, 27 insertions(+), 4 deletions(-) diff --git a/oceanum/storage/filesystem.py b/oceanum/storage/filesystem.py index 163a692..0038b07 100644 --- a/oceanum/storage/filesystem.py +++ b/oceanum/storage/filesystem.py @@ -130,20 +130,43 @@ async def set_session(self): weakref.finalize(self, self.close_session, self.loop, self._session) return self._session - async def _ls(self, path="", detail=True, **kwargs): + async def _ls(self, + path="", + detail=True, + file_prefix=None, + match_glob=None, + limit=None, + **kwargs + ): logger.debug(path) session = await self.set_session() spath = path.lstrip("/") - async with session.get(self._base_url + spath, **kwargs) as r: + params = {} + + if limit: + params["limit"] = limit + if file_prefix: + params["file_prefix"] = file_prefix + if match_glob: + params["match_glob"] = match_glob + + async with session.get(self._base_url + spath, params=params or None) as r: try: self._raise_not_found_for_status(r, path) except ( FileNotFoundError ): # The storage endpoint enforces trailing slash for directories, so test for that - if path[-1] == "/": + if path.endswith("/"): raise FileNotFoundError(path) else: - return await self._ls(path + "/", detail=detail, **kwargs) + return await self._ls( + path + "/", + detail=detail, + file_prefix=file_prefix, + match_glob=match_glob, + limit=limit, + **kwargs + ) listing = await r.json() if not listing: raise FileNotFoundError(path)