Skip to content

Commit 15bf7ff

Browse files
authored
Track if files are writable and disable saving if they are not. (#164)
1 parent d397f76 commit 15bf7ff

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

jupyter_server_documents/rooms/yroom_file_api.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,7 @@ def __init__(self, *args, **kwargs):
105105
self._last_path = None
106106
self._last_modified = None
107107
self._stopped = False
108+
self._is_writable = True
108109

109110
# Initialize content-related primitives
110111
self._content_loading = False
@@ -199,6 +200,10 @@ async def _load_content(self, jupyter_ydoc: YBaseDoc) -> None:
199200
format=self.file_format
200201
))
201202

203+
# The content manager uses this to tell consumers of the API if the file is writable.
204+
# We need to save this so we can use it during save.
205+
self._is_writable = file_data.get('writable', True)
206+
202207
if self.file_type == "notebook":
203208
self.log.info(f"Processing outputs for loaded notebook: '{self.room_id}'.")
204209
file_data = self.outputs_manager.process_loaded_notebook(file_id=self.file_id, file_data=file_data)
@@ -364,6 +369,9 @@ async def save(self, jupyter_ydoc: YBaseDoc):
364369
instead.
365370
"""
366371
try:
372+
# Return immediately if the content manager has marked this file as non-writable
373+
if not self._is_writable:
374+
return
367375
# Build arguments to `CM.save()`
368376
path = self.get_path()
369377
content = jupyter_ydoc.source

0 commit comments

Comments
 (0)