mirror of
https://github.com/Zagrios/bs-manager.git
synced 2026-07-03 14:08:25 +02:00
[bugfix] check if symlink is supported on current filesystem before linking
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user