Skip to content

Commit

Permalink
Run pre_save_hook before model check (#643)
Browse files Browse the repository at this point in the history
  • Loading branch information
davidbrochart committed Dec 22, 2021
1 parent 4d2f85a commit e789676
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 13 deletions.
13 changes: 6 additions & 7 deletions jupyter_server/services/contents/filemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -433,6 +433,8 @@ def save(self, model, path=""):
"""Save the file model and return the model with no content."""
path = path.strip("/")

self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if "content" not in model and model["type"] != "directory":
Expand All @@ -441,8 +443,6 @@ def save(self, model, path=""):
os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)

self.run_pre_save_hook(model=model, path=path)

try:
if model["type"] == "notebook":
nb = nbformat.from_dict(model["content"])
Expand Down Expand Up @@ -757,16 +757,15 @@ async def save(self, model, path=""):
"""Save the file model and return the model with no content."""
path = path.strip("/")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if "content" not in model and model["type"] != "directory":
raise web.HTTPError(400, u"No file content provided")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)

self.run_pre_save_hook(model=model, path=path)

try:
if model["type"] == "notebook":
nb = nbformat.from_dict(model["content"])
Expand Down
13 changes: 7 additions & 6 deletions jupyter_server/services/contents/largefilemanager.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ def save(self, model, path=""):
if chunk is not None:
path = path.strip("/")

self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if model["type"] != "file":
Expand All @@ -31,11 +33,10 @@ def save(self, model, path=""):
raise web.HTTPError(400, u"No file content provided")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)

try:
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
super(LargeFileManager, self)._save_file(
os_path, model["content"], model.get("format")
)
Expand Down Expand Up @@ -90,6 +91,10 @@ async def save(self, model, path=""):
if chunk is not None:
path = path.strip("/")

os_path = self._get_os_path(path)
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)

if "type" not in model:
raise web.HTTPError(400, u"No file type provided")
if model["type"] != "file":
Expand All @@ -102,12 +107,8 @@ async def save(self, model, path=""):
if "content" not in model and model["type"] != "directory":
raise web.HTTPError(400, u"No file content provided")

os_path = self._get_os_path(path)

try:
if chunk == 1:
self.log.debug("Saving %s", os_path)
self.run_pre_save_hook(model=model, path=path)
await super(AsyncLargeFileManager, self)._save_file(
os_path, model["content"], model.get("format")
)
Expand Down

0 comments on commit e789676

Please sign in to comment.