diff --git a/jupyter_server/services/contents/filemanager.py b/jupyter_server/services/contents/filemanager.py index 54e2dca38d..8980437c87 100644 --- a/jupyter_server/services/contents/filemanager.py +++ b/jupyter_server/services/contents/filemanager.py @@ -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": @@ -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"]) @@ -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"]) diff --git a/jupyter_server/services/contents/largefilemanager.py b/jupyter_server/services/contents/largefilemanager.py index 5c2b6b28b6..28c3ffce50 100644 --- a/jupyter_server/services/contents/largefilemanager.py +++ b/jupyter_server/services/contents/largefilemanager.py @@ -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": @@ -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") ) @@ -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": @@ -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") )