From a3aaf6f78e1cf5334bd25ad902e5399c2838194d Mon Sep 17 00:00:00 2001 From: Robert Aboukhalil Date: Wed, 25 Aug 2021 17:19:22 -0700 Subject: [PATCH] Abstract out filesystem setup function so it can be called in case apps want to enable custom behavior (e.g. add a new tool after Aioli was initialized) --- src/worker.js | 73 ++++++++++++++++++++++++++++----------------------- 1 file changed, 40 insertions(+), 33 deletions(-) diff --git a/src/worker.js b/src/worker.js index 9370cbc..b26b6a6 100644 --- a/src/worker.js +++ b/src/worker.js @@ -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; @@ -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}`);