diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-09-23 21:11:07 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2020-10-14 11:20:37 +0200 |
commit | ec396c77079b9f2fb43748b12285a5fec6f905e2 (patch) | |
tree | 8dd48e70b45669689e376e6550d38b886121857e /platform/javascript | |
parent | 6769dd64fc5430e8c34295cb41434bff734a5155 (diff) |
[HTML5] Close IDBFS database on exit.
This should be made available in emscripten in a decent way.
Possibly after unmount, to free the database lock and allow performing
operations on it from javascript after the Emscripten Runtime has
exited.
Diffstat (limited to 'platform/javascript')
-rw-r--r-- | platform/javascript/engine/engine.js | 1 | ||||
-rw-r--r-- | platform/javascript/native/utils.js | 21 |
2 files changed, 19 insertions, 3 deletions
diff --git a/platform/javascript/engine/engine.js b/platform/javascript/engine/engine.js index f8e216db2d..05a11701c0 100644 --- a/platform/javascript/engine/engine.js +++ b/platform/javascript/engine/engine.js @@ -121,6 +121,7 @@ Function('return this')()['Engine'] = (function() { me.rtenv['noExitRuntime'] = true; me.rtenv['onExecute'] = me.onExecute; me.rtenv['onExit'] = function(code) { + me.rtenv['deinitFS'](); if (me.onExit) me.onExit(code); me.rtenv = null; diff --git a/platform/javascript/native/utils.js b/platform/javascript/native/utils.js index 0b3698fd86..8d0beba454 100644 --- a/platform/javascript/native/utils.js +++ b/platform/javascript/native/utils.js @@ -29,8 +29,7 @@ /*************************************************************************/ Module['initFS'] = function(persistentPaths) { - FS.mkdir('/userfs'); - FS.mount(IDBFS, {}, '/userfs'); + Module.mount_points = ['/userfs'].concat(persistentPaths); function createRecursive(dir) { try { @@ -43,13 +42,14 @@ Module['initFS'] = function(persistentPaths) { } } - persistentPaths.forEach(function(path) { + Module.mount_points.forEach(function(path) { createRecursive(path); FS.mount(IDBFS, {}, path); }); return new Promise(function(resolve, reject) { FS.syncfs(true, function(err) { if (err) { + Module.mount_points = []; Module.idbfs = false; console.log("IndexedDB not available: " + err.message); } else { @@ -60,6 +60,21 @@ Module['initFS'] = function(persistentPaths) { }); }; +Module['deinitFS'] = function() { + Module.mount_points.forEach(function(path) { + try { + FS.unmount(path); + } catch (e) { + console.log("Already unmounted", e); + } + if (Module.idbfs && IDBFS.dbs[path]) { + IDBFS.dbs[path].close(); + delete IDBFS.dbs[path]; + } + }); + Module.mount_points = []; +}; + Module['copyToFS'] = function(path, buffer) { var p = path.lastIndexOf("/"); var dir = "/"; |