Skip to content

Commit

Permalink
[PB-1645] fix: Check if directories (root and temp) exists on start …
Browse files Browse the repository at this point in the history
…fuseapp
  • Loading branch information
JoanVicens authored Feb 29, 2024
2 parents e546275 + 9adc3a7 commit 7a7857f
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 4 deletions.
5 changes: 3 additions & 2 deletions src/apps/fuse/FuseApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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');
Expand Down Expand Up @@ -72,11 +73,11 @@ export class FuseApp {

async start(): Promise<void> {
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,
});

Expand Down
15 changes: 13 additions & 2 deletions src/apps/shared/fs/ensure-folder-exists.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
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);
} 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}`);
}

}
}

0 comments on commit 7a7857f

Please sign in to comment.