Skip to content

Commit 475a8c5

Browse files
committed
add backend function to check existance of object
1 parent 10412ee commit 475a8c5

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

jupyter_drives/manager.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -542,6 +542,27 @@ async def presigned_link(self, drive_name, path):
542542
}
543543
return response
544544

545+
async def check_file(self, drive_name, path):
546+
"""Check if an object already exists within a drive.
547+
548+
Args:
549+
drive_name: name of drive where object exists
550+
path: path where content is located
551+
"""
552+
# eliminate leading and trailing backslashes
553+
path = path.strip('/')
554+
check = await self._file_system._exists(drive_name + '/' + path)
555+
if check == False:
556+
# check if we are dealing with a directory
557+
check = await self._file_system._exists(drive_name + '/' + path + EMPTY_DIR_SUFFIX)
558+
if check == False:
559+
raise tornado.web.HTTPError(
560+
status_code= httpx.codes.NOT_FOUND,
561+
reason="Object does not already exist within drive.",
562+
)
563+
564+
return
565+
545566
async def _get_drive_location(self, drive_name):
546567
"""Helping function for getting drive region.
547568

0 commit comments

Comments
 (0)