From: Jérôme Benoit Date: Wed, 25 Jan 2023 22:24:54 +0000 (+0100) Subject: Improve empty file name handling X-Git-Tag: v1.1.92~10 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=c78355e4f754d07a9d150b10b11ad925946b5c5a;p=e-mobility-charging-stations-simulator.git Improve empty file name handling Signed-off-by: Jérôme Benoit --- diff --git a/src/types/FileType.ts b/src/types/FileType.ts index b464bf8b..3781b7d9 100644 --- a/src/types/FileType.ts +++ b/src/types/FileType.ts @@ -4,4 +4,5 @@ export enum FileType { ChargingStationConfiguration = 'charging station configuration', ChargingStationTemplate = 'charging station template', PerformanceRecords = 'performance records', + JsonSchema = 'json schema', } diff --git a/src/utils/Configuration.ts b/src/utils/Configuration.ts index 1c51bbfd..5df7bdc5 100644 --- a/src/utils/Configuration.ts +++ b/src/utils/Configuration.ts @@ -373,7 +373,7 @@ export default class Configuration { private static getConfigurationFileWatcher(): fs.FSWatcher | undefined { try { return fs.watch(Configuration.configurationFile, (event, filename): void => { - if (filename && event === 'change') { + if (filename.trim().length !== 0 && event === 'change') { // Nullify to force configuration file reading Configuration.configuration = null; if (!Configuration.isUndefined(Configuration.configurationChangeCallback)) { diff --git a/src/utils/FileUtils.ts b/src/utils/FileUtils.ts index 2e99f52f..5bb22e7d 100644 --- a/src/utils/FileUtils.ts +++ b/src/utils/FileUtils.ts @@ -20,7 +20,7 @@ export default class FileUtils { file: string, refreshedVariable?: T, listener: fs.WatchListener = (event, filename) => { - if (filename && event === 'change') { + if (!Utils.isEmptyString(filename) && event === 'change') { try { logger.debug(`${logPrefix} ${fileType} file ${file} have changed, reload`); refreshedVariable && (refreshedVariable = JSON.parse(fs.readFileSync(file, 'utf8')) as T); @@ -32,7 +32,7 @@ export default class FileUtils { } } ): fs.FSWatcher | undefined { - if (file) { + if (!Utils.isEmptyString(file)) { try { return fs.watch(file, listener); } catch (error) {