refactor: revert internal exports
[e-mobility-charging-stations-simulator.git] / src / performance / storage / JsonFileStorage.ts
index fb7062674bb2ea14787a2d5eb0ff6646bab75d11..e94d79b97d337826bcc4c7bc74d698d5211b1e04 100644 (file)
@@ -1,10 +1,11 @@
 // Copyright Jerome Benoit. 2021-2023. All Rights Reserved.
 
 import fs from 'node:fs';
+import path from 'node:path';
 
+import { Storage } from './Storage';
 import { FileType, type Statistics } from '../../types';
 import { AsyncLock, AsyncLockType, Constants, FileUtils, Utils } from '../../utils';
-import { Storage } from '../internal';
 
 export class JsonFileStorage extends Storage {
   private fd: number | null = null;
@@ -45,6 +46,9 @@ export class JsonFileStorage extends Storage {
   public open(): void {
     try {
       if (Utils.isNullOrUndefined(this?.fd)) {
+        if (!fs.existsSync(path.dirname(this.dbName))) {
+          fs.mkdirSync(path.dirname(this.dbName), { recursive: true });
+        }
         this.fd = fs.openSync(this.dbName, 'a+');
       }
     } catch (error) {