Skip to content

Commit

Permalink
Fix mounting logic
Browse files Browse the repository at this point in the history
  • Loading branch information
martinRenou committed Sep 6, 2024
1 parent 9bef843 commit 641a3a0
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 69 deletions.
38 changes: 20 additions & 18 deletions src/coincident.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -44,27 +44,29 @@ export class XeusCoincidentKernel extends XeusRemoteKernel {
/**
* Setup custom Emscripten FileSystem
*/
protected async initFilesystem(
options: IXeusWorkerKernel.IOptions
async mount(
driveName: string,
mountpoint: string,
baseUrl: string
): Promise<void> {
if (options.mountDrive) {
const mountpoint = '/drive';
const { FS, PATH, ERRNO_CODES } = globalThis.Module;
const { baseUrl } = options;
const { FS, PATH, ERRNO_CODES } = globalThis.Module;

const driveFS = new XeusDriveFS({
FS,
PATH,
ERRNO_CODES,
baseUrl,
driveName: this._driveName,
mountpoint
});
FS.mkdir(mountpoint);
FS.mount(driveFS, {}, mountpoint);
FS.chdir(mountpoint);
this._driveFS = driveFS;
if (!FS) {
return;
}

const drive = new XeusDriveFS({
FS,
PATH,
ERRNO_CODES,
baseUrl,
driveName,
mountpoint
});

FS.mkdir(mountpoint);
FS.mount(drive, {}, mountpoint);
FS.chdir(mountpoint);
}
}

Expand Down
40 changes: 20 additions & 20 deletions src/comlink.worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,6 @@ import {
ServiceWorkerContentsAPI
} from '@jupyterlite/contents';

import { IXeusWorkerKernel } from './tokens';

import { XeusRemoteKernel } from './worker';

/**
Expand All @@ -36,27 +34,29 @@ export class XeusComlinkKernel extends XeusRemoteKernel {
/**
* Setup custom Emscripten FileSystem
*/
protected async initFilesystem(
options: IXeusWorkerKernel.IOptions
async mount(
driveName: string,
mountpoint: string,
baseUrl: string
): Promise<void> {
if (options.mountDrive) {
const mountpoint = '/drive';
const { FS, PATH, ERRNO_CODES } = globalThis.Module;
const { baseUrl } = options;
const { FS, PATH, ERRNO_CODES } = globalThis.Module;

const driveFS = new XeusDriveFS({
FS,
PATH,
ERRNO_CODES,
baseUrl,
driveName: this._driveName,
mountpoint
});
FS.mkdir(mountpoint);
FS.mount(driveFS, {}, mountpoint);
FS.chdir(mountpoint);
this._driveFS = driveFS;
if (!FS) {
return;
}

const drive = new XeusDriveFS({
FS,
PATH,
ERRNO_CODES,
baseUrl,
driveName,
mountpoint
});

FS.mkdir(mountpoint);
FS.mount(drive, {}, mountpoint);
FS.chdir(mountpoint);
}
}

Expand Down
7 changes: 5 additions & 2 deletions src/web_worker_kernel.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@

import coincident from 'coincident';

import { Remote, proxy, wrap } from 'comlink';
import { wrap } from 'comlink';
import type { Remote } from 'comlink';

import { ISignal, Signal } from '@lumino/signaling';
import { PromiseDelegate } from '@lumino/coreutils';
Expand Down Expand Up @@ -90,8 +91,10 @@ export class WebWorkerKernel implements IKernel {
return await this._contentsProcessor.processDriveRequest(data);
};
} else {
this._worker.onmessage = e => {
this._processWorkerMessage(e.data);
};
remote = wrap(this._worker) as Remote<IXeusWorkerKernel>;
remote.registerCallback(proxy(this._processWorkerMessage.bind(this)));
}
remote
.initialize({
Expand Down
29 changes: 0 additions & 29 deletions src/worker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -157,38 +157,9 @@ export class XeusRemoteKernel {
}
}

await this.initFilesystem(options);

kernelReady(1);
}

/**
* Setup custom Emscripten FileSystem
*/
protected async initFilesystem(
options: IXeusWorkerKernel.IOptions
): Promise<void> {
if (options.mountDrive) {
const mountpoint = '/drive';
const { FS, PATH, ERRNO_CODES } = globalThis.Module;
const { baseUrl } = options;
const { DriveFS } = await import('@jupyterlite/contents');

const driveFS = new DriveFS({
FS,
PATH,
ERRNO_CODES,
baseUrl,
driveName: this._driveName,
mountpoint
});
FS.mkdir(mountpoint);
FS.mount(driveFS, {}, mountpoint);
FS.chdir(mountpoint);
this._driveFS = driveFS;
}
}

/**
* Register the callback function to send messages from the worker back to the main thread.
* @param callback the callback to register
Expand Down

0 comments on commit 641a3a0

Please sign in to comment.