From: Jérôme Benoit Date: Mon, 19 Jun 2023 21:46:29 +0000 (+0200) Subject: fix: ensure id tags cache is properly cleaned X-Git-Tag: v1.2.17~16 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=26a17d9368bd65430bea2a04d23df8ebe84aeac2;p=e-mobility-charging-stations-simulator.git fix: ensure id tags cache is properly cleaned Signed-off-by: Jérôme Benoit --- 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(