Skip to content

Commit

Permalink
Abstract out filesystem setup function so it can be called in case ap…
Browse files Browse the repository at this point in the history
…ps want to enable custom behavior (e.g. add a new tool after Aioli was initialized)
  • Loading branch information
robertaboukhalil committed Aug 26, 2021
1 parent cf39e6d commit a3aaf6f
Showing 1 changed file with 40 additions and 33 deletions.
73 changes: 40 additions & 33 deletions src/worker.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,39 +45,8 @@ const aioli = {
// Initialize WebAssembly modules (downloads .wasm/.js/.json in parallel)
await Promise.all(aioli.tools.map(tool => this._setup(tool)));

// Some tools have preloaded files mounted to their filesystems to hold sample data (e.g. /samtools/examples/).
// By default, those are only accessible from the filesystem of the respective tool. Here, we want to allow
// other modules to also have access to those sample data files.
for(let i in aioli.tools)
{
// Skip base module
if(i == 0)
continue;

for(let j in aioli.tools)
{
// Skip base module and self
if(j == 0 || i == j)
continue;

const fsSrc = aioli.tools[i].module.FS;
const fsDst = aioli.tools[j].module.FS;

// Make sure source tool actually has such a folder (must be the same as the "module", not "program").
// Skip if the destination filesystem already has that folder (could theoretically happen if initialize)
// two copies of the same module.
const path = `/${aioli.tools[i].tool}`;
if(!fsSrc.analyzePath(path).exists || fsDst.analyzePath(path).exists)
continue;

aioli._log(`Mounting ${path} onto ${aioli.tools[j].tool} filesystem`);
fsDst.mkdir(path);
fsDst.mount(aioli.tools[0].module.PROXYFS, {
root: path,
fs: fsSrc
}, path);
}
}
// Setup filesystems so that tools can access each other's sample data
await this._setupFS();

aioli._log("Ready");
return true;
Expand Down Expand Up @@ -293,6 +262,44 @@ const aioli = {
tool.ready = true;
},

// Setup filesystems so that tools can access each other's sample data
async _setupFS()
{
// Some tools have preloaded files mounted to their filesystems to hold sample data (e.g. /samtools/examples/).
// By default, those are only accessible from the filesystem of the respective tool. Here, we want to allow
// other modules to also have access to those sample data files.
for(let i in aioli.tools)
{
// Skip base module
if(i == 0)
continue;

for(let j in aioli.tools)
{
// Skip base module and self
if(j == 0 || i == j)
continue;

const fsSrc = aioli.tools[i].module.FS;
const fsDst = aioli.tools[j].module.FS;

// Make sure source tool actually has such a folder (must be the same as the "module", not "program").
// Skip if the destination filesystem already has that folder (could theoretically happen if initialize)
// two copies of the same module.
const path = `/${aioli.tools[i].tool}`;
if(!fsSrc.analyzePath(path).exists || fsDst.analyzePath(path).exists)
continue;

aioli._log(`Mounting ${path} onto ${aioli.tools[j].tool} filesystem`);
fsDst.mkdir(path);
fsDst.mount(aioli.tools[0].module.PROXYFS, {
root: path,
fs: fsSrc
}, path);
}
}
},

// Common file operations
_fileop(operation, path) {
aioli._log(`Running ${operation} ${path}`);
Expand Down

0 comments on commit a3aaf6f

Please sign in to comment.