Skip to content

Commit cd7191b

Browse files
committed
fix bug in jupyter read-only detection, which only happened when using whiteboard+jupyter
1 parent 72b9034 commit cd7191b

File tree

2 files changed

+24
-15
lines changed

2 files changed

+24
-15
lines changed

src/packages/jupyter/redux/actions.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ export abstract class JupyterActions extends Actions<JupyterStoreState> {
183183
sync_read_only = (): void => {
184184
if (this._state == "closed") return;
185185
const a = this.store.get("read_only");
186-
const b = this.syncdb != null ? this.syncdb.is_read_only() : undefined;
186+
const b = this.syncdb?.is_read_only();
187187
if (a !== b) {
188188
this.setState({ read_only: b });
189189
this.set_cm_options();

src/packages/sync/editor/generic/sync-doc.ts

Lines changed: 23 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1559,28 +1559,37 @@ export class SyncDoc extends EventEmitter {
15591559
await Promise.all(v);
15601560
};
15611561

1562-
private async file_is_read_only(): Promise<boolean> {
1562+
private pathExistsAndIsReadOnly = async (path): Promise<boolean> => {
15631563
try {
15641564
await callback2(this.client.path_access, {
1565-
path: this.path,
1565+
path,
15661566
mode: "w",
15671567
});
1568-
// also check on the original file in case of Jupyter:
1569-
const path = this.getFileServerPath();
1570-
if (path != this.path) {
1571-
await callback2(this.client.path_access, {
1572-
path,
1573-
mode: "w",
1574-
});
1575-
}
1576-
// no error -- it is NOT read only
1568+
// clearly exists and is NOT read only:
15771569
return false;
15781570
} catch (err) {
1579-
this.dbg("file_is_read_only")(err);
1580-
// error -- it is read only.
1571+
// either it doesn't exist or it is read only
1572+
if (await callback2(this.client.path_exists, { path })) {
1573+
// it exists, so is read only and exists
1574+
return true;
1575+
}
1576+
// doesn't exist
1577+
return false;
1578+
}
1579+
};
1580+
1581+
private file_is_read_only = async (): Promise<boolean> => {
1582+
if (await this.pathExistsAndIsReadOnly(this.path)) {
15811583
return true;
15821584
}
1583-
}
1585+
const path = this.getFileServerPath();
1586+
if (path != this.path) {
1587+
if (await this.pathExistsAndIsReadOnly(path)) {
1588+
return true;
1589+
}
1590+
}
1591+
return false;
1592+
};
15841593

15851594
private update_if_file_is_read_only = async (): Promise<void> => {
15861595
this.set_read_only(await this.file_is_read_only());

0 commit comments

Comments
 (0)