0
0
Fork 0

Check if existing oldConfigPath is a Symlink (#5271)

This commit is contained in:
siegmund-heiss-ich 2023-06-09 15:31:19 +02:00 committed by GitHub
parent e94d24f508
commit f7ec310231
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -96,7 +96,7 @@ namespace Ryujinx.Common.Configuration
if (OperatingSystem.IsMacOS() && Mode == LaunchMode.UserProfile) if (OperatingSystem.IsMacOS() && Mode == LaunchMode.UserProfile)
{ {
string oldConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), DefaultBaseDir); string oldConfigPath = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), DefaultBaseDir);
if (Path.Exists(oldConfigPath) && !Path.Exists(BaseDirPath)) if (Path.Exists(oldConfigPath) && !IsPathSymlink(oldConfigPath) && !Path.Exists(BaseDirPath))
{ {
CopyDirectory(oldConfigPath, BaseDirPath); CopyDirectory(oldConfigPath, BaseDirPath);
Directory.Delete(oldConfigPath, true); Directory.Delete(oldConfigPath, true);
@ -115,6 +115,14 @@ namespace Ryujinx.Common.Configuration
Directory.CreateDirectory(KeysDirPath = Path.Combine(BaseDirPath, KeysDir)); Directory.CreateDirectory(KeysDirPath = Path.Combine(BaseDirPath, KeysDir));
} }
// Check if existing old baseDirPath is a symlink, to prevent possible errors.
// Should be removed, when the existance of the old directory isn't checked anymore.
private static bool IsPathSymlink(string path)
{
FileAttributes attributes = File.GetAttributes(path);
return (attributes & FileAttributes.ReparsePoint) == FileAttributes.ReparsePoint;
}
private static void CopyDirectory(string sourceDir, string destinationDir) private static void CopyDirectory(string sourceDir, string destinationDir)
{ {
var dir = new DirectoryInfo(sourceDir); var dir = new DirectoryInfo(sourceDir);