File tree Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Expand file tree Collapse file tree 2 files changed +24
-15
lines changed Original file line number Diff line number Diff line change @@ -183,7 +183,7 @@ export abstract class JupyterActions extends Actions<JupyterStoreState> {
183
183
sync_read_only = ( ) : void => {
184
184
if ( this . _state == "closed" ) return ;
185
185
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 ( ) ;
187
187
if ( a !== b ) {
188
188
this . setState ( { read_only : b } ) ;
189
189
this . set_cm_options ( ) ;
Original file line number Diff line number Diff line change @@ -1559,28 +1559,37 @@ export class SyncDoc extends EventEmitter {
1559
1559
await Promise . all ( v ) ;
1560
1560
} ;
1561
1561
1562
- private async file_is_read_only ( ) : Promise < boolean > {
1562
+ private pathExistsAndIsReadOnly = async ( path ) : Promise < boolean > = > {
1563
1563
try {
1564
1564
await callback2 ( this . client . path_access , {
1565
- path : this . path ,
1565
+ path,
1566
1566
mode : "w" ,
1567
1567
} ) ;
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:
1577
1569
return false ;
1578
1570
} 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 ) ) {
1581
1583
return true ;
1582
1584
}
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
+ } ;
1584
1593
1585
1594
private update_if_file_is_read_only = async ( ) : Promise < void > => {
1586
1595
this . set_read_only ( await this . file_is_read_only ( ) ) ;
You can’t perform that action at this time.
0 commit comments