[bugfix] check if symlink is supported on current filesystem before linking

This commit is contained in:
MathieuG-P
2025-01-14 16:23:45 +01:00
parent e4766f8a25
commit e3fef23ef0
12 changed files with 42 additions and 2 deletions
+31 -1
View File
@@ -3,10 +3,13 @@ import log from "electron-log";
import { deleteFolder, ensureFolderExist, moveFolderContent, pathExist, unlinkPath } from "../helpers/fs.helpers";
import { lstat, symlink } from "fs/promises";
import path from "path";
import { copy, readlink } from "fs-extra";
import { copy, mkdirSync, readlink, rmSync, symlinkSync, unlinkSync } from "fs-extra";
import { lastValueFrom } from "rxjs";
import { noop } from "shared/helpers/function.helpers";
import { StaticConfigurationService } from "./static-configuration.service";
import { randomUUID } from "crypto";
import { CustomError } from "shared/models/exceptions/custom-error.class";
import { tryit } from "shared/helpers/error.helpers";
export class FolderLinkerService {
private static instance: FolderLinkerService;
@@ -41,6 +44,29 @@ export class FolderLinkerService {
}
}
public isLinkingSupported(): boolean {
const uuid = randomUUID();
const installationPath = this.installLocationService.installationDirectory();
const testFolder = path.join(installationPath, uuid);
const testLink = path.join(installationPath, `${uuid}_link`);
const resLink = tryit(() => {
mkdirSync(testFolder);
symlinkSync(testFolder, testLink, this.getLinkingType());
});
tryit(() => {
rmSync(testFolder, { force: true, recursive: true });
unlinkSync(testLink);
});
if(resLink.error){
log.error("Unable to create symlink", resLink.error);
}
return !resLink.error;
}
public sharedFolder(): string {
return this.installLocationService.sharedContentPath();
}
@@ -74,6 +100,10 @@ export class FolderLinkerService {
}
public async linkFolder(folderPath: string, options?: LinkOptions): Promise<void> {
if(!this.isLinkingSupported()){
throw new CustomError("Linking is not supported on this platform", "LinkingNotSupported");
}
const sharedPath = await this.getSharedFolder(folderPath, options?.intermediateFolder);
if (await this.isFolderSymlink(folderPath)) {
@@ -21,7 +21,7 @@ export class VersionFolderLinkerService {
return VersionFolderLinkerService.instance;
}
private readonly KNOWN_ERROR_CODES = ["EPERM", "EACCES", "ENOSPC"];
private readonly KNOWN_ERROR_CODES = ["EPERM", "EACCES", "ENOSPC", "LinkingNotSupported"];
private readonly ipcService: IpcService;
private readonly progress: ProgressBarService;