From 26a17d9368bd65430bea2a04d23df8ebe84aeac2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Mon, 19 Jun 2023 23:46:29 +0200 Subject: [PATCH] fix: ensure id tags cache is properly cleaned MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/charging-station/IdTagsCache.ts | 8 +++++--- .../ocpp/OCPPIncomingRequestService.ts | 12 ++++++++---- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/src/charging-station/IdTagsCache.ts b/src/charging-station/IdTagsCache.ts index 890ac1fb..6e8592cb 100644 --- a/src/charging-station/IdTagsCache.ts +++ b/src/charging-station/IdTagsCache.ts @@ -70,7 +70,7 @@ export class IdTagsCache { } public deleteIdTags(file: string): boolean { - return this.deleteIdTagsCache(file); + return this.deleteIdTagsCache(file) && this.deleteIdTagsCacheIndexes(file); } private getRandomIdTag(hashId: string, file: string): string { @@ -155,12 +155,14 @@ export class IdTagsCache { return this.idTagsCaches.delete(file); } - private deleteIdTagsCacheIndexes(file: string): void { + private deleteIdTagsCacheIndexes(file: string): boolean { + let deleted: boolean[]; for (const [key] of this.idTagsCachesAddressableIndexes) { if (key.startsWith(file)) { - this.idTagsCachesAddressableIndexes.delete(key); + deleted.push(this.idTagsCachesAddressableIndexes.delete(key)); } } + return !deleted.some((value) => value === false); } private getIdTagsCacheIndexesAddressableKey(prefix: string, uid: string): string { diff --git a/src/charging-station/ocpp/OCPPIncomingRequestService.ts b/src/charging-station/ocpp/OCPPIncomingRequestService.ts index 2a304c31..390feda8 100644 --- a/src/charging-station/ocpp/OCPPIncomingRequestService.ts +++ b/src/charging-station/ocpp/OCPPIncomingRequestService.ts @@ -104,10 +104,14 @@ export abstract class OCPPIncomingRequestService extends AsyncResource { } protected handleRequestClearCache(chargingStation: ChargingStation): ClearCacheResponse { - chargingStation.idTagsCache.deleteIdTags( - ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo) - ); - return OCPPConstants.OCPP_RESPONSE_ACCEPTED; + if ( + chargingStation.idTagsCache.deleteIdTags( + ChargingStationUtils.getIdTagsFile(chargingStation.stationInfo) + ) + ) { + return OCPPConstants.OCPP_RESPONSE_ACCEPTED; + } + return OCPPConstants.OCPP_RESPONSE_REJECTED; } public abstract incomingRequestHandler( -- 2.34.1