Browse Source

Add symlink handling for unix

pull/55/head
Ionite 1 year ago
parent
commit
7ecdd99de5
No known key found for this signature in database
  1. 7
      StabilityMatrix.Core/Helper/Compat.cs
  2. 17
      StabilityMatrix.Core/Helper/SharedFolders.cs

7
StabilityMatrix.Core/Helper/Compat.cs

@ -1,6 +1,7 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Runtime.InteropServices;
using System.Runtime.Versioning;
using StabilityMatrix.Core.Models.FileInterfaces;
namespace StabilityMatrix.Core.Helper;
@ -15,8 +16,14 @@ public static class Compat
// OS Platform
public static PlatformKind Platform { get; }
[SupportedOSPlatformGuard("Windows")]
public static bool IsWindows => Platform.HasFlag(PlatformKind.Windows);
[SupportedOSPlatformGuard("Linux")]
public static bool IsLinux => Platform.HasFlag(PlatformKind.Linux);
[SupportedOSPlatformGuard("macOS")]
public static bool IsMacOS => Platform.HasFlag(PlatformKind.MacOS);
public static bool IsUnix => Platform.HasFlag(PlatformKind.Unix);

17
StabilityMatrix.Core/Helper/SharedFolders.cs

@ -20,6 +20,19 @@ public class SharedFolders : ISharedFolders
this.settingsManager = settingsManager;
this.packageFactory = packageFactory;
}
// Platform redirect for junctions / symlinks
private static void CreateLinkOrJunction(string junctionDir, string targetDir, bool overwrite)
{
if (Compat.IsWindows)
{
Junction.Create(junctionDir, targetDir, overwrite);
}
else
{
Directory.CreateSymbolicLink(junctionDir, targetDir);
}
}
public static void SetupLinks(Dictionary<SharedFolderType, string> definitions,
DirectoryPath modelsDirectory, DirectoryPath installDirectory)
@ -55,7 +68,7 @@ public class SharedFolders : ISharedFolders
destinationDir.Delete(true);
}
Logger.Info($"Creating junction link from {sourceDir} to {destinationDir}");
Junction.Create(destinationDir, sourceDir, true);
CreateLinkOrJunction(destinationDir, sourceDir, true);
}
}
@ -92,7 +105,7 @@ public class SharedFolders : ISharedFolders
Directory.Delete(destination, false);
}
Logger.Info($"Updating junction link from {source} to {destination}");
Junction.Create(destination, source, true);
CreateLinkOrJunction(destination, source, true);
}
}

Loading…
Cancel
Save