Skip to content

Commit 21b84a7

Browse files
committed
add function to check directory with boto
1 parent 1bf9683 commit 21b84a7

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

jupyter_drives/manager.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,30 @@ def _get_drive_location(self, drive_name):
294294

295295
return location
296296

297+
def _check_object(self, drive_name, path):
298+
"""Helping function to check if we are dealing with an empty file or directory.
299+
300+
Args:
301+
drive_name: name of drive where object exists
302+
path: path to object to check
303+
"""
304+
isDir = False
305+
try:
306+
location = self._content_managers[drive_name]["location"]
307+
if location not in self._s3_clients:
308+
self._s3_clients[location] = self._s3_session.client('s3', location)
309+
310+
listing = self._s3_clients[location].list_objects_v2(Bucket = drive_name, Prefix = path + '/')
311+
if 'Contents' in listing:
312+
isDir = True
313+
except Exception as e:
314+
raise tornado.web.HTTPError(
315+
status_code= httpx.codes.BAD_REQUEST,
316+
reason=f"The following error occured when retriving the drive location: {e}",
317+
)
318+
319+
return isDir
320+
297321
async def _call_provider(
298322
self,
299323
url: str,

0 commit comments

Comments
 (0)