Skip to content

Commit f16d5ab

Browse files
committed
Add support for saving file when under a sub-directory
1 parent f642d7b commit f16d5ab

File tree

1 file changed

+9
-7
lines changed

1 file changed

+9
-7
lines changed

src/drive.ts

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,13 @@ export class FileSystemDrive implements Contents.IDrive {
177177
throw new Error('No root file handle');
178178
}
179179

180-
const handle = await root.getFileHandle(path);
180+
let parentHandle = root;
181+
// If saving a file that is not under root, we need the right directory handle
182+
for (const subPath of path.split('/').slice(0, -1)) {
183+
parentHandle = await parentHandle.getDirectoryHandle(subPath);
184+
}
185+
186+
const handle = await parentHandle.getFileHandle(PathExt.basename(path));
181187
const writable = await handle.createWritable({});
182188

183189
const format = options?.format;
@@ -196,18 +202,14 @@ export class FileSystemDrive implements Contents.IDrive {
196202
throw new Error('Method not implemented.');
197203
}
198204

199-
async createCheckpoint(
200-
path: string
201-
): Promise<Contents.ICheckpointModel> {
205+
async createCheckpoint(path: string): Promise<Contents.ICheckpointModel> {
202206
return {
203207
id: 'test',
204208
last_modified: new Date().toISOString()
205209
};
206210
}
207211

208-
async listCheckpoints(
209-
path: string
210-
): Promise<Contents.ICheckpointModel[]> {
212+
async listCheckpoints(path: string): Promise<Contents.ICheckpointModel[]> {
211213
return [
212214
{
213215
id: 'test',

0 commit comments

Comments
 (0)