Merge pull request #739 from Zagrios/bugfix/check-if-symlink-is-supported-before-linking

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

(cherry picked from commit 4b8004ea80)
This commit is contained in:
MathieuG-P
2025-01-18 01:13:18 +01:00
parent 0b7272b4ba
commit 2c06184b65
10 changed files with 41 additions and 3 deletions
+1
View File
@@ -499,6 +499,7 @@
"EPERM": "BSManager hat nicht die erforderlichen Berechtigungen, um den Ordner zu verknüpfen.",
"EACCES": "BSManager hat nicht die erforderlichen Berechtigungen, um den Ordner zu verknüpfen.",
"ENOSPC": "Die Festplatte ist voll, machen Sie Platz und versuchen Sie es erneut.",
"LinkingNotSupported": "Ordnerverknüpfung wird auf diesem Dateisystem nicht unterstützt.",
"UNKNOWN_ERROR": "Ein unbekannter Fehler ist beim Verknüpfen des Ordners aufgetreten."
}
}
+2 -1
View File
@@ -499,7 +499,8 @@
"EPERM": "BSManager does not have the necessary permissions to link the folder.",
"EACCES": "BSManager does not have the necessary permissions to link the folder.",
"ENOSPC": "The disk is full, make some space and try again.",
"UNKNOWN_ERROR":"An unknown error has occurred while linking the folder."
"UNKNOWN_ERROR":"An unknown error has occurred while linking the folder.",
"LinkingNotSupported": "Folder linking is not supported on this file system."
}
}
},
+1
View File
@@ -499,6 +499,7 @@
"EPERM": "BSManager no tiene los permisos necesarios para enlazar la carpeta.",
"EACCES": "BSManager no tiene los permisos necesarios para enlazar la carpeta.",
"ENOSPC": "El disco está lleno, libera espacio e inténtalo de nuevo.",
"LinkingNotSupported": "El enlace de carpetas no es compatible con este sistema de archivos.",
"UNKNOWN_ERROR": "Se ha producido un error desconocido al enlazar la carpeta."
}
}
+1
View File
@@ -499,6 +499,7 @@
"EPERM": "BSManager n'a pas les autorisations nécessaires pour lier le dossier.",
"EACCES": "BSManager n'a pas les autorisations nécessaires pour lier le dossier.",
"ENOSPC": "Le disque est plein, faites de la place et réessayez.",
"LinkingNotSupported": "La liaison de dossier n'est pas supportée sur ce système de fichiers.",
"UNKNOWN_ERROR": "Une erreur inconnue est survenue lors de la liaison du dossier."
}
}
+1
View File
@@ -499,6 +499,7 @@
"EPERM": "BSManagerにはフォルダをリンクするための必要な権限がありません。",
"EACCES": "BSManagerにはフォルダをリンクするための必要な権限がありません。",
"ENOSPC": "ディスクがいっぱいです。空き容量を作ってもう一度試してください。",
"LinkingNotSupported": "このファイルシステムではフォルダのリンクはサポートされていません。",
"UNKNOWN_ERROR": "フォルダをリンク中に不明なエラーが発生しました。"
}
}
+1
View File
@@ -499,6 +499,7 @@
"EPERM": "BSManager не имеет необходимых прав для связывания папки.",
"EACCES": "BSManager не имеет необходимых прав для связывания папки.",
"ENOSPC": "Диск заполнен, освободите место и попробуйте снова.",
"LinkingNotSupported": "Ссылки на папки не поддерживаются в этой файловой системе.",
"UNKNOWN_ERROR": "Произошла неизвестная ошибка при связывании папки."
}
}
+1
View File
@@ -499,6 +499,7 @@
"EPERM": "BSManager沒有必要的權限來連結文件夾。",
"EACCES": "BSManager沒有必要的權限來連結文件夾。",
"ENOSPC": "磁碟已滿,請騰出空間後再試。",
"LinkingNotSupported": "該檔案系統不支援資料夾連結。",
"UNKNOWN_ERROR": "連結文件夾時發生未知錯誤。"
}
}
+1
View File
@@ -499,6 +499,7 @@
"EPERM": "BSManager没有必要的权限来链接文件夹。",
"EACCES": "BSManager没有必要的权限来链接文件夹。",
"ENOSPC": "磁盘已满,请腾出空间后再试。",
"LinkingNotSupported": "该文件系统不支持文件夹链接。",
"UNKNOWN_ERROR": "链接文件夹时发生未知错误。"
}
}
+31 -1
View File
@@ -3,9 +3,12 @@ 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 { randomUUID } from "crypto";
import { tryit } from "shared/helpers/error.helpers";
import { CustomError } from "shared/models/exceptions/custom-error.class";
export class FolderLinkerService {
private static instance: FolderLinkerService;
@@ -51,7 +54,34 @@ export class FolderLinkerService {
});
}
public async isLinkingSupported(): Promise<boolean> {
const uuid = randomUUID();
const installationPath = await this.installLocationService.installationDirectory();
const testFolder = path.join(installationPath, uuid);
const testLink = path.join(installationPath, `${uuid}_link`);
const resLink = tryit(() => {
mkdirSync(testFolder);
symlinkSync(testFolder, testLink, "junction");
});
tryit(() => {
rmSync(testFolder, { force: true, recursive: true });
unlinkSync(testLink);
});
if(resLink.error){
log.error("Unable to create symlink", resLink.error);
}
return !resLink.error;
}
public async linkFolder(folderPath: string, options?: LinkOptions): Promise<void> {
if(!(await 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;