diff --git a/IPython/html/services/contents/filemanager.py b/IPython/html/services/contents/filemanager.py index ef23d00..7fe4ee8 100644 --- a/IPython/html/services/contents/filemanager.py +++ b/IPython/html/services/contents/filemanager.py @@ -252,7 +252,7 @@ class FileCheckpointManager(FileManagerMixin, CheckpointManager): def get_checkpoint(self, checkpoint_id, path, type): """Get the content of a checkpoint. - Returns a pair of (content, type). + Returns a model suitable for passing to ContentsManager.save. """ path = path.strip('/') self.log.info("restoring %s from checkpoint %s", path, checkpoint_id) @@ -260,9 +260,20 @@ class FileCheckpointManager(FileManagerMixin, CheckpointManager): if not os.path.isfile(os_checkpoint_path): self.no_such_checkpoint(path, checkpoint_id) if type == 'notebook': - return self._read_notebook(os_checkpoint_path, as_version=4), None + return { + 'type': type, + 'content': self._read_notebook( + os_checkpoint_path, + as_version=4, + ), + } else: - return self._read_file(os_checkpoint_path, format=None) + content, format = self._read_file(os_checkpoint_path, format=None) + return { + 'type': type, + 'content': content, + 'format': format, + } def rename_checkpoint(self, checkpoint_id, old_path, new_path): """Rename a checkpoint from old_path to new_path.""" diff --git a/IPython/html/services/contents/manager.py b/IPython/html/services/contents/manager.py index 1a7d29c..ec2f7db 100644 --- a/IPython/html/services/contents/manager.py +++ b/IPython/html/services/contents/manager.py @@ -523,19 +523,14 @@ class ContentsManager(LoggingConfigurable): """ Restore a checkpoint. """ - type = self.get(path, content=False)['type'] - content, format = self.checkpoint_manager.get_checkpoint( - checkpoint_id, - path, - type, + return self.save( + model=self.checkpoint_manager.get_checkpoint( + checkpoint_id, + path, + self.get(path, content=False)['type'] + ), + path=path, ) - model = { - 'type': type, - 'content': content, - 'format': format, - } - return self.save(model, path) - def delete_checkpoint(self, checkpoint_id, path): return self.checkpoint_manager.delete_checkpoint(checkpoint_id, path)