Merge pull request #1853 from thelounge/xpaw/clear-storage

Clear storage folder after successful start and graceful exit
This commit is contained in:
Jérémie Astori 2017-12-18 19:31:46 -05:00 committed by GitHub
commit 95ff256e68
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 0 deletions

View File

@ -9,7 +9,9 @@ const helper = require("../helper");
class Storage {
constructor() {
this.references = new Map();
}
emptyDir() {
// Ensures that a directory is empty.
// Deletes directory contents if the directory is not empty.
// If the directory does not exist, it is created.

View File

@ -146,6 +146,12 @@ module.exports = function() {
return;
}
if (Helper.config.prefetchStorage) {
log.info("Clearing prefetch storage folder, this might take a while...");
require("./plugins/storage").emptyDir();
}
// Forcefully exit after 3 seconds
suicideTimeout = setTimeout(() => process.exit(1), 3000);
@ -163,6 +169,11 @@ module.exports = function() {
process.on("SIGINT", exitGracefully);
process.on("SIGTERM", exitGracefully);
// Clear storage folder after server starts successfully
if (Helper.config.prefetchStorage) {
require("./plugins/storage").emptyDir();
}
});
return server;