-import fs from 'node:fs';
+import { type FSWatcher, readFileSync } from 'node:fs';
import type { ChargingStation } from './ChargingStation';
import { ChargingStationUtils } from './ChargingStationUtils';
type IdTagsCacheValueType = {
idTags: string[];
- idTagsFileWatcher: fs.FSWatcher | undefined;
+ idTagsFileWatcher: FSWatcher | undefined;
};
export class IdTagsCache {
}
/**
- * Get one idtag from the cache given the distribution
+ * Gets one idtag from the cache given the distribution
* Must be called after checking the cache is not an empty array
*
* @param distribution -
}
/**
- * Get all idtags from the cache
+ * Gets all idtags from the cache
* Must be called after checking the cache is not an empty array
*
* @param file -
}
public deleteIdTags(file: string): boolean {
- return this.deleteIdTagsCache(file);
+ return this.deleteIdTagsCache(file) && this.deleteIdTagsCacheIndexes(file);
}
private getRandomIdTag(hashId: string, file: string): string {
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 {
private getIdTagsFromFile(file: string): string[] {
if (Utils.isNotEmptyString(file)) {
try {
- return JSON.parse(fs.readFileSync(file, 'utf8')) as string[];
+ return JSON.parse(readFileSync(file, 'utf8')) as string[];
} catch (error) {
handleFileException(
file,