diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 7d54b755cd..ab686c1495 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -158,6 +158,7 @@ namespace Tgstation.Server.Host.Core else { services.AddSingleton(); + services.AddSingleton(); } services.AddSingleton(); diff --git a/src/Tgstation.Server.Host/IO/PosixSymlinkFactory.cs b/src/Tgstation.Server.Host/IO/PosixSymlinkFactory.cs new file mode 100644 index 0000000000..90a00410be --- /dev/null +++ b/src/Tgstation.Server.Host/IO/PosixSymlinkFactory.cs @@ -0,0 +1,27 @@ +using Mono.Unix; +using System.IO; +using System.Threading; +using System.Threading.Tasks; + +namespace Tgstation.Server.Host.IO +{ + /// + /// for posix systems + /// + sealed class PosixSymlinkFactory : ISymlinkFactory + { + /// + public Task CreateSymbolicLink(string targetPath, string linkPath, CancellationToken cancellationToken) => Task.Factory.StartNew(() => + { + UnixFileSystemInfo fsInfo; + var isFile = File.Exists(targetPath); + cancellationToken.ThrowIfCancellationRequested(); + if (isFile) + fsInfo = new UnixFileInfo(targetPath); + else + fsInfo = new UnixDirectoryInfo(targetPath); + cancellationToken.ThrowIfCancellationRequested(); + fsInfo.CreateSymbolicLink(linkPath); + }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + } +} diff --git a/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs b/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs index 09243bdcce..824b5375f5 100644 --- a/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs +++ b/src/Tgstation.Server.Host/IO/WindowsSymlinkFactory.cs @@ -18,6 +18,7 @@ namespace Tgstation.Server.Host.IO var flags = File.Exists(targetPath) ? 0 : 1; //SYMBOLIC_LINK_FLAG_DIRECTORY flags |= 2; //SYMBOLIC_LINK_FLAG_ALLOW_UNPRIVILEGED_CREATE on win10 1607+ + cancellationToken.ThrowIfCancellationRequested(); if (!NativeMethods.CreateSymbolicLink(linkPath, targetPath, flags)) throw new Win32Exception(Marshal.GetLastWin32Error()); }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current);