From 63d719b3b575e3cbb3e44e00be33234e82917530 Mon Sep 17 00:00:00 2001 From: Vishwas Shashidhar Date: Fri, 15 Jan 2021 16:17:19 +0530 Subject: [PATCH] SDA-2875: add defense for statSync in logger (#1173) --- src/common/logger.ts | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/common/logger.ts b/src/common/logger.ts index 724cd7b5..d41bbe65 100644 --- a/src/common/logger.ts +++ b/src/common/logger.ts @@ -251,10 +251,12 @@ class Logger { const deleteTimeStamp = new Date().getTime() - (5 * 24 * 60 * 60 * 1000); files.forEach((file) => { const filePath = path.join(this.logPath, file); - const stat = fs.statSync(filePath); - const fileTimestamp = new Date(util.inspect(stat.mtime)).getTime(); - if ((fileTimestamp < deleteTimeStamp) && fs.existsSync(filePath)) { - fs.unlinkSync(filePath); + if (fs.existsSync(filePath)) { + const stat = fs.statSync(filePath); + const fileTimestamp = new Date(util.inspect(stat.mtime)).getTime(); + if ((fileTimestamp < deleteTimeStamp)) { + fs.unlinkSync(filePath); + } } }); }