fix: ensure id tags cache is properly cleaned
authorJérôme Benoit <jerome.benoit@sap.com>
Mon, 19 Jun 2023 21:46:29 +0000 (23:46 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Mon, 19 Jun 2023 21:46:29 +0000 (23:46 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/charging-station/IdTagsCache.ts
src/charging-station/ocpp/OCPPIncomingRequestService.ts

index 890ac1fbf12892a04c7afcde3e27d04f09845154..6e8592cb71aecfeb7f3160212761905adde2b9c8 100644 (file)
@@ -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 {
index 2a304c31f118e138ab716150cc893d7ea0db9161..390feda8fbc6f7930964e884bddbf0061ec8ada5 100644 (file)
@@ -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(