Skip to content

Commit

Permalink
Merge pull request #64 from DenisaCG/checkFile
Browse files Browse the repository at this point in the history
Update logic to check existence of object
  • Loading branch information
DenisaCG authored Dec 18, 2024
2 parents 10412ee + c6c4d5c commit f789bf7
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 3 deletions.
21 changes: 21 additions & 0 deletions jupyter_drives/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -542,6 +542,27 @@ async def presigned_link(self, drive_name, path):
}
return response

async def check_file(self, drive_name, path):
"""Check if an object already exists within a drive.
Args:
drive_name: name of drive where object exists
path: path where content is located
"""
# eliminate leading and trailing backslashes
path = path.strip('/')
check = await self._file_system._exists(drive_name + '/' + path)
if check == False:
# check if we are dealing with a directory
check = await self._file_system._exists(drive_name + '/' + path + EMPTY_DIR_SUFFIX)
if check == False:
raise tornado.web.HTTPError(
status_code= httpx.codes.NOT_FOUND,
reason="Object does not already exist within drive.",
)

return

async def _get_drive_location(self, drive_name):
"""Helping function for getting drive region.
Expand Down
9 changes: 6 additions & 3 deletions src/requests.ts
Original file line number Diff line number Diff line change
Expand Up @@ -475,7 +475,7 @@ export const countObjectNameAppearances = async (
path: string,
originalName: string
): Promise<number> => {
let counter: number = 0;
let dirCount: { [fileName: string]: number } = {};
path = path.substring(0, path.lastIndexOf('/'));

const response = await requestAPI<any>(
Expand All @@ -489,11 +489,14 @@ export const countObjectNameAppearances = async (
if (
fileName.substring(0, originalName.length + 1).includes(originalName)
) {
counter += 1;
dirCount[fileName] = 1;
}
});
}

const counter = Object.values(dirCount).reduce(
(sum, count) => sum + count,
0
);
return counter;
};

Expand Down

0 comments on commit f789bf7

Please sign in to comment.