1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

[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.
This commit is contained in:
Fabio Alessandrelli
2020-09-23 21:11:07 +02:00
parent 47e82bcb58
commit 1bfc582633
2 changed files with 19 additions and 3 deletions

View File

@@ -121,6 +121,7 @@ Function('return this')()['Engine'] = (function() {
me.rtenv['noExitRuntime'] = true; me.rtenv['noExitRuntime'] = true;
me.rtenv['onExecute'] = me.onExecute; me.rtenv['onExecute'] = me.onExecute;
me.rtenv['onExit'] = function(code) { me.rtenv['onExit'] = function(code) {
me.rtenv['deinitFS']();
if (me.onExit) if (me.onExit)
me.onExit(code); me.onExit(code);
me.rtenv = null; me.rtenv = null;

View File

@@ -29,8 +29,7 @@
/*************************************************************************/ /*************************************************************************/
Module['initFS'] = function(persistentPaths) { Module['initFS'] = function(persistentPaths) {
FS.mkdir('/userfs'); Module.mount_points = ['/userfs'].concat(persistentPaths);
FS.mount(IDBFS, {}, '/userfs');
function createRecursive(dir) { function createRecursive(dir) {
try { try {
@@ -43,13 +42,14 @@ Module['initFS'] = function(persistentPaths) {
} }
} }
persistentPaths.forEach(function(path) { Module.mount_points.forEach(function(path) {
createRecursive(path); createRecursive(path);
FS.mount(IDBFS, {}, path); FS.mount(IDBFS, {}, path);
}); });
return new Promise(function(resolve, reject) { return new Promise(function(resolve, reject) {
FS.syncfs(true, function(err) { FS.syncfs(true, function(err) {
if (err) { if (err) {
Module.mount_points = [];
Module.idbfs = false; Module.idbfs = false;
console.log("IndexedDB not available: " + err.message); console.log("IndexedDB not available: " + err.message);
} else { } 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) { Module['copyToFS'] = function(path, buffer) {
var p = path.lastIndexOf("/"); var p = path.lastIndexOf("/");
var dir = "/"; var dir = "/";