From 78b44eab0a4d2fbfd5c29984dcad6b1b0600bd0f Mon Sep 17 00:00:00 2001 From: Leon Krause Date: Tue, 27 Mar 2018 09:14:03 +0200 Subject: [PATCH] Fix engine.js preloadFile() with directories (cherry picked from commit 6f1bddf4b5e6716f59bcbd9a7587b6d556251ef9) --- platform/javascript/engine.js | 16 +++++++++++++--- 1 file changed, 13 insertions(+), 3 deletions(-) diff --git a/platform/javascript/engine.js b/platform/javascript/engine.js index 527587c7c5d..afd912bf396 100644 --- a/platform/javascript/engine.js +++ b/platform/javascript/engine.js @@ -1,3 +1,4 @@ + exposedLibs['PATH'] = PATH; exposedLibs['FS'] = FS; return Module; }, @@ -96,14 +97,14 @@ } if (pathOrBuffer instanceof Uint8Array) { preloadedFiles.push({ - name: bufferFilename, + path: bufferFilename, buffer: pathOrBuffer }); return Promise.resolve(); } else if (typeof pathOrBuffer === 'string') { return loadPromise(pathOrBuffer, preloadProgressTracker).then(function(xhr) { preloadedFiles.push({ - name: pathOrBuffer, + path: pathOrBuffer, buffer: xhr.response }); }); @@ -178,7 +179,16 @@ this.rtenv.thisProgram = executableName || getBaseName(basePath); preloadedFiles.forEach(function(file) { - LIBS.FS.createDataFile('/', file.name, new Uint8Array(file.buffer), true, true, true); + var dir = LIBS.PATH.dirname(file.path); + try { + LIBS.FS.stat(dir); + } catch (e) { + if (e.code !== 'ENOENT') { + throw e; + } + LIBS.FS.mkdirTree(dir); + } + LIBS.FS.createDataFile('/', file.path, new Uint8Array(file.buffer), true, true, true); }, this); preloadedFiles = null;