Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Change md5 to hash and hash_algorithm, fix incompatibility #1367

Merged
merged 16 commits into from Nov 24, 2023
3 changes: 3 additions & 0 deletions jupyter_server/services/contents/filemanager.py
Expand Up @@ -48,6 +48,7 @@ class FileContentsManager(FileManagerMixin, ContentsManager):
root_dir = Unicode(config=True)

max_copy_folder_size_mb = Int(500, config=True, help="The max folder size that can be copied")
support_md5 = Bool(True, config=False, help="Support md5 argument in `get`")

@default("root_dir")
def _default_root_dir(self):
Expand Down Expand Up @@ -725,6 +726,8 @@ def _human_readable_size(self, size):
class AsyncFileContentsManager(FileContentsManager, AsyncFileManagerMixin, AsyncContentsManager):
"""An async file contents manager."""

support_md5 = Bool(True, config=False, help="Support md5 argument in `get`")

@default("checkpoints_class")
def _checkpoints_class_default(self):
return AsyncFileCheckpoints
Expand Down
19 changes: 10 additions & 9 deletions jupyter_server/services/contents/handlers.py
Expand Up @@ -145,16 +145,17 @@ async def get(self, path=""):
await self._finish_error(
HTTPStatus.NOT_FOUND, f"file or directory {path!r} does not exist"
)
kwargs = {
"path": path,
"type": type,
"format": format,
"content": content,
}
if cm.support_md5:
kwargs["md5"] = md5

Wh1isper marked this conversation as resolved.
Show resolved Hide resolved
try:
model = await ensure_async(
self.contents_manager.get(
path=path,
type=type,
format=format,
content=content,
md5=md5,
)
)
model = await ensure_async(self.contents_manager.get(**kwargs))
validate_model(model, expect_content=content, expect_md5=md5)
self._finish_model(model, location=False)
except web.HTTPError as exc:
Expand Down
19 changes: 16 additions & 3 deletions jupyter_server/services/contents/manager.py
Expand Up @@ -111,6 +111,7 @@ def _validate_preferred_dir(self, proposal):
return value

allow_hidden = Bool(False, config=True, help="Allow access to hidden files")
support_md5 = Bool(False, config=False, help="Support md5 argument in `get`")

notary = Instance(sign.NotebookNotary)

Expand Down Expand Up @@ -447,8 +448,14 @@ def exists(self, path):
"""
return self.file_exists(path) or self.dir_exists(path)

def get(self, path, content=True, type=None, format=None, md5=False):
"""Get a file or directory model."""
def get(self, path, content=True, type=None, format=None):
"""
Get a file or directory model.

If a ContentManager supports calculating the md5 value of a file,
`ContentManager.support_md5` should be True and this function will accept an `md5` parameter,
will return a dict with an `md5` key.
"""
raise NotImplementedError

def save(self, model, path):
Expand Down Expand Up @@ -850,7 +857,13 @@ async def exists(self, path):
)

async def get(self, path, content=True, type=None, format=None):
"""Get a file or directory model."""
"""
Get a file or directory model.

If a ContentManager supports calculating the md5 value of a file,
ContentManager.support_md5 should be True and this function will accept an md5 parameter,
will return a dict with an 'md5' key.
"""
raise NotImplementedError

async def save(self, model, path):
Expand Down