From c06fb9a27545f4dcb9ca56468f82d2fbed87ae66 Mon Sep 17 00:00:00 2001 From: Pavel Djundik Date: Mon, 18 Dec 2017 16:58:43 +0200 Subject: [PATCH] Clear storage folder after successful start and graceful exit --- src/plugins/storage.js | 2 ++ src/server.js | 11 +++++++++++ 2 files changed, 13 insertions(+) diff --git a/src/plugins/storage.js b/src/plugins/storage.js index b96bf7af..4d2a8f90 100644 --- a/src/plugins/storage.js +++ b/src/plugins/storage.js @@ -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. diff --git a/src/server.js b/src/server.js index 744ed4a4..9d719d08 100644 --- a/src/server.js +++ b/src/server.js @@ -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;