diff options
author | RaindropsSys <contact@minteck.org> | 2023-06-02 16:31:02 +0200 |
---|---|---|
committer | RaindropsSys <contact@minteck.org> | 2023-06-02 16:31:02 +0200 |
commit | 48afc99d05c7bcd54231f340635f5102a03fbda4 (patch) | |
tree | bdad312490ee42b84dde71d5c49266f1b7fc792e /includes/external/chvfs/index.js | |
parent | 82ef2e6f4fadb6ed721a0de79ec4d2fcfdc3f426 (diff) | |
download | pluralconnect-48afc99d05c7bcd54231f340635f5102a03fbda4.tar.gz pluralconnect-48afc99d05c7bcd54231f340635f5102a03fbda4.tar.bz2 pluralconnect-48afc99d05c7bcd54231f340635f5102a03fbda4.zip |
Updated 7 files, added error.php and deleted 39 files (automated)
Diffstat (limited to 'includes/external/chvfs/index.js')
-rw-r--r-- | includes/external/chvfs/index.js | 107 |
1 files changed, 0 insertions, 107 deletions
diff --git a/includes/external/chvfs/index.js b/includes/external/chvfs/index.js deleted file mode 100644 index fda57bf..0000000 --- a/includes/external/chvfs/index.js +++ /dev/null @@ -1,107 +0,0 @@ -let active = true; -let queue = []; - -const watch = require('node-watch'); -const child_process = require('child_process'); -const fs = require('fs').promises; -const fss = require('fs'); -const path = require('path'); - -process.on('uncaughtException', (e) => { - console.error(e); -}); - -function start() { - console.log("Mounting chvfs..."); - child_process.execSync("mount -t tmpfs -o size=1G chvfs /_ch"); - console.log("Mounted chvfs to /_ch"); - - console.log("Preparing filesystem..."); - child_process.execSync("cp -r /opt/peh_save/* /_ch"); - child_process.execSync("chmod -Rf 777 /_ch"); - console.log("Filesystem is ready"); - - console.log("Watching for changes..."); - watch("/_ch", { recursive: true }, (event, filename) => { - try { - if (!active || !filename) return; - - if (event === "update") { - console.log(filename + " was created or affected"); - - queue.push({ - file: filename, - remove: false - }); - } else if (event === "remove") { - console.log(filename + " was dropped"); - - queue.push({ - file: filename, - remove: true - }); - } - } catch (e) { - console.error(e); - } - }) -} - -function stop() { - active = false; - - console.log("Unmounting chvfs..."); - child_process.execSync("umount -l /_ch"); - console.log("Unmounted chvfs"); -} - -start(); -setInterval(async () => { - for (let item of queue) { - try { - if (item.remove) { - console.log("Dropping " + item.file); - await fs.unlink("/opt/peh_save/" + item.file.substring(5)); - } else { - console.log("Copying " + item.file); - try { await fs.mkdir(path.dirname(item.file), { recursive: true }); } catch (e) {} - await fs.copyFile(item.file, "/opt/peh_save/" + item.file.substring(5)); - } - } catch (e) { - console.error(e); - } - - queue.splice(0, 1); - } -}); - -process.on('exit', () => { - process.stdout.write("\n"); - - for (let item of queue) { - try { - if (item.remove) { - console.log("Dropping " + item.file); - fss.unlinkSync("/opt/peh_save/" + item.file.substring(5)); - } else { - console.log("Copying " + item.file); - try { fss.mkdirSync(path.dirname(item.file), { recursive: true }); } catch (e) {} - fss.copyFileSync(item.file, "/opt/peh_save/" + item.file.substring(5)); - } - } catch (e) { - console.error(e); - } - - queue.splice(0, 1); - } - - stop(); -}); - -process.on('SIGINT', () => { - process.exit(); -}); - -process.on('SIGTERM', () => { - process.exit(); -});
\ No newline at end of file |