Skip to content

Commit f789bf7

Browse files
authored
Merge pull request #64 from DenisaCG/checkFile
Update logic to check existence of object
2 parents 10412ee + c6c4d5c commit f789bf7

File tree

2 files changed

+27
-3
lines changed

2 files changed

+27
-3
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

src/requests.ts

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -475,7 +475,7 @@ export const countObjectNameAppearances = async (
475475
path: string,
476476
originalName: string
477477
): Promise<number> => {
478-
let counter: number = 0;
478+
let dirCount: { [fileName: string]: number } = {};
479479
path = path.substring(0, path.lastIndexOf('/'));
480480

481481
const response = await requestAPI<any>(
@@ -489,11 +489,14 @@ export const countObjectNameAppearances = async (
489489
if (
490490
fileName.substring(0, originalName.length + 1).includes(originalName)
491491
) {
492-
counter += 1;
492+
dirCount[fileName] = 1;
493493
}
494494
});
495495
}
496-
496+
const counter = Object.values(dirCount).reduce(
497+
(sum, count) => sum + count,
498+
0
499+
);
497500
return counter;
498501
};
499502

0 commit comments

Comments
 (0)