From 03ca20ed27d7dc6d1d4124f1fde631bab9201ece Mon Sep 17 00:00:00 2001 From: Luis De Andrade Date: Wed, 7 Feb 2024 09:52:55 +0000 Subject: [PATCH 1/2] fix: Check if directories (root and temp) exists on start fuseapp --- src/apps/fuse/FuseApp.ts | 5 +++-- src/apps/shared/fs/ensure-folder-exists.ts | 16 ++++++++++++++-- 2 files changed, 17 insertions(+), 4 deletions(-) diff --git a/src/apps/fuse/FuseApp.ts b/src/apps/fuse/FuseApp.ts index fc589f7de..9174ae3c9 100644 --- a/src/apps/fuse/FuseApp.ts +++ b/src/apps/fuse/FuseApp.ts @@ -11,6 +11,7 @@ import { TrashFolderCallback } from './callbacks/TrashFolderCallback'; import { WriteCallback } from './callbacks/WriteCallback'; import { ReleaseCallback } from './callbacks/ReleaseCallback'; import { FuseDependencyContainer } from './dependency-injection/FuseDependencyContainer'; +import { ensureFolderExists } from './../shared/fs/ensure-folder-exists'; // eslint-disable-next-line @typescript-eslint/no-var-requires const fuse = require('@gcas/fuse'); @@ -72,11 +73,11 @@ export class FuseApp { async start(): Promise { const ops = await this.getOpt(); + ensureFolderExists(this.paths.root); + ensureFolderExists(this.paths.local); this._fuse = new fuse(this.paths.root, ops, { debug: false, - mkdir: true, - force: true, maxRead: FuseApp.MAX_INT_32, }); diff --git a/src/apps/shared/fs/ensure-folder-exists.ts b/src/apps/shared/fs/ensure-folder-exists.ts index ef941bdee..d2e1b127e 100644 --- a/src/apps/shared/fs/ensure-folder-exists.ts +++ b/src/apps/shared/fs/ensure-folder-exists.ts @@ -1,5 +1,17 @@ -import { PathLike, mkdirSync } from 'fs'; +import { PathLike, accessSync, mkdirSync, constants } from 'fs'; +import Logger from 'electron-log'; export function ensureFolderExists(folder: PathLike) { - mkdirSync(folder, { recursive: true }); + try { + accessSync(folder, constants.F_OK); + Logger.info(`Folder <${folder}> already exists`); + } catch (err) { + Logger.info(`Folder <${folder}> does not exists, going to create it`); + try { + mkdirSync(folder, { recursive: true }); + } catch (err) { + Logger.error(`Error creating the folder <${folder}>, ${err}`); + } + + } } From 9adc3a72c1e77ef01c186178cdf5f915853bbcad Mon Sep 17 00:00:00 2001 From: Luis De Andrade Date: Thu, 8 Feb 2024 10:58:12 +0000 Subject: [PATCH 2/2] delete continuos logger message --- src/apps/shared/fs/ensure-folder-exists.ts | 1 - 1 file changed, 1 deletion(-) diff --git a/src/apps/shared/fs/ensure-folder-exists.ts b/src/apps/shared/fs/ensure-folder-exists.ts index d2e1b127e..f48b4beb4 100644 --- a/src/apps/shared/fs/ensure-folder-exists.ts +++ b/src/apps/shared/fs/ensure-folder-exists.ts @@ -4,7 +4,6 @@ import Logger from 'electron-log'; export function ensureFolderExists(folder: PathLike) { try { accessSync(folder, constants.F_OK); - Logger.info(`Folder <${folder}> already exists`); } catch (err) { Logger.info(`Folder <${folder}> does not exists, going to create it`); try {