From fb3d962cfd8eff3d560967c507d881accdfcee71 Mon Sep 17 00:00:00 2001 From: Dmitry Gorelenkov Date: Sun, 15 Mar 2020 21:09:11 +0100 Subject: [PATCH] fix(logger): close opened fd in '.setWrite()' windows does not really unlink file, if fd is opened. (see https://stackoverflow.com/a/20801823/2519073) the unit tests failing because of this --- lib/logger.ts | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/lib/logger.ts b/lib/logger.ts index 12f007b1e..5a2da8289 100644 --- a/lib/logger.ts +++ b/lib/logger.ts @@ -68,6 +68,14 @@ export class Logger { if (opt_logFile) { logFile = opt_logFile; } + + // if fd already opened, close it + // need it for windows, https://stackoverflow.com/a/20801823/2519073 + if (typeof Logger.fd === 'number') { + fs.closeSync(Logger.fd); + Logger.fd = void 0; + } + Logger.writeTo = writeTo; if (Logger.writeTo == WriteTo.FILE || Logger.writeTo == WriteTo.BOTH) { Logger.fd = fs.openSync(path.resolve(logFile), 'a');