@@ -4,6 +4,9 @@ import { PathExt } from '@jupyterlab/coreutils';
4
4
5
5
import { ISignal , Signal } from '@lumino/signaling' ;
6
6
7
+ export const DRIVE_NAME = 'FileSystem' ;
8
+ const DRIVE_PREFIX = `${ DRIVE_NAME } :` ;
9
+
7
10
function arrayBufferToBase64 ( buffer : ArrayBuffer ) : string {
8
11
let binary = '' ;
9
12
const bytes = new Uint8Array ( buffer ) ;
@@ -41,7 +44,7 @@ export class FileSystemDrive implements Contents.IDrive {
41
44
}
42
45
43
46
get name ( ) : string {
44
- return 'FileSystem' ;
47
+ return DRIVE_NAME ;
45
48
}
46
49
47
50
get serverSettings ( ) : ServerConnection . ISettings {
@@ -64,6 +67,8 @@ export class FileSystemDrive implements Contents.IDrive {
64
67
path : string ,
65
68
options ?: Contents . IFetchOptions
66
69
) : Promise < Contents . IModel > {
70
+ path = this . cleanPath ( path ) ;
71
+
67
72
const root = this . _rootHandle ;
68
73
69
74
if ( ! root ) {
@@ -140,16 +145,20 @@ export class FileSystemDrive implements Contents.IDrive {
140
145
async newUntitled (
141
146
options ?: Contents . ICreateOptions
142
147
) : Promise < Contents . IModel > {
148
+ let parentPath = '' ;
149
+ if ( options && options . path ) {
150
+ parentPath = this . cleanPath ( options . path ) ;
151
+ }
152
+
143
153
const type = options ?. type || 'directory' ;
144
154
const path = PathExt . join (
145
- options ?. path || '' ,
155
+ parentPath ,
146
156
type === 'directory' ? 'Untitled Folder' : 'untitled'
147
157
) ;
148
158
const ext = options ?. ext || 'txt' ;
149
159
150
160
const parentHandle = await this . getParentHandle ( path ) ;
151
161
152
- const parentPath = PathExt . dirname ( path ) ;
153
162
let localPath = PathExt . basename ( path ) ;
154
163
const name = localPath ;
155
164
@@ -186,6 +195,8 @@ export class FileSystemDrive implements Contents.IDrive {
186
195
}
187
196
188
197
async delete ( path : string ) : Promise < void > {
198
+ path = this . cleanPath ( path ) ;
199
+
189
200
const parentHandle = await this . getParentHandle ( path ) ;
190
201
191
202
await parentHandle . removeEntry ( PathExt . basename ( path ) , { recursive : true } ) ;
@@ -199,6 +210,9 @@ export class FileSystemDrive implements Contents.IDrive {
199
210
200
211
async rename ( oldPath : string , newPath : string ) : Promise < Contents . IModel > {
201
212
// Best effort, we are lacking proper APIs for renaming
213
+ oldPath = this . cleanPath ( oldPath ) ;
214
+ newPath = this . cleanPath ( newPath ) ;
215
+
202
216
await this . doCopy ( oldPath , newPath ) ;
203
217
204
218
await this . delete ( oldPath ) ;
@@ -210,6 +224,8 @@ export class FileSystemDrive implements Contents.IDrive {
210
224
path : string ,
211
225
options ?: Partial < Contents . IModel >
212
226
) : Promise < Contents . IModel > {
227
+ path = this . cleanPath ( path ) ;
228
+
213
229
const parentHandle = await this . getParentHandle ( path ) ;
214
230
215
231
if ( options ?. type === 'directory' ) {
@@ -240,6 +256,8 @@ export class FileSystemDrive implements Contents.IDrive {
240
256
241
257
async copy ( path : string , toLocalDir : string ) : Promise < Contents . IModel > {
242
258
// Best effort, we are lacking proper APIs for copying
259
+ path = this . cleanPath ( path ) ;
260
+
243
261
const toCopy = await this . get ( path ) ;
244
262
const parentPath = PathExt . dirname ( path ) ;
245
263
@@ -373,7 +391,7 @@ export class FileSystemDrive implements Contents.IDrive {
373
391
}
374
392
375
393
private async doCopy ( oldPath : string , newPath : string ) : Promise < void > {
376
- // Best effort, we are lacking proper APIs for copying
394
+ // Best effort, we are lacking proper APIs for copying
377
395
const oldParentHandle = await this . getParentHandle ( oldPath ) ;
378
396
379
397
const oldLocalPath = PathExt . basename ( oldPath ) ;
@@ -414,6 +432,13 @@ export class FileSystemDrive implements Contents.IDrive {
414
432
}
415
433
}
416
434
435
+ private cleanPath ( path : string ) : string {
436
+ if ( path . includes ( DRIVE_PREFIX ) ) {
437
+ return path . replace ( DRIVE_PREFIX , '' ) ;
438
+ }
439
+ return path ;
440
+ }
441
+
417
442
private _isDisposed = false ;
418
443
private _fileChanged = new Signal < Contents . IDrive , Contents . IChangedArgs > (
419
444
this
0 commit comments