SDA-2875: add defense for statSync in logger (#1173)

This commit is contained in:
Vishwas Shashidhar 2021-01-15 16:17:19 +05:30 committed by GitHub
parent 2c947ed41c
commit 63d719b3b5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -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);
}
}
});
}