tgstation-server 6.8.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
WindowsFilesystemLinkFactory.cs
Go to the documentation of this file.
1using System;
2using System.IO;
3using System.Threading;
4using System.Threading.Tasks;
5
6using BetterWin32Errors;
7
9
11{
16 {
19
21 public Task CreateHardLink(string targetPath, string linkPath, CancellationToken cancellationToken)
22 => throw new NotSupportedException();
23
25 public Task CreateSymbolicLink(string targetPath, string linkPath, CancellationToken cancellationToken) => Task.Factory.StartNew(
26 () =>
27 {
28 ArgumentNullException.ThrowIfNull(targetPath);
29 ArgumentNullException.ThrowIfNull(linkPath);
30
31 // check if its not a file
32 var flags = File.Exists(targetPath) ? NativeMethods.CreateSymbolicLinkFlags.None : NativeMethods.CreateSymbolicLinkFlags.Directory;
33
34 /*
35 * no don't fucking use this
36 * sure it works in SOME cases
37 * i.e. win10 1803+ and IN DEVELOPER MODE
38 * other times it throws ERROR_INVALID_PARAMETER
39 * but the fucking worst is there are some configurations of windows that accept the argument and allow the function to succeed
40 * BUT IT DOESN'T CREATE THE FUCKING LINK
41 * I AM NOT DEBUGGING THAT SHIT AGAIN AHHH
42
43 flags |= NativeMethods.CreateSymbolicLinkFlags.AllowUnprivilegedCreate;
44 */
45
46 cancellationToken.ThrowIfCancellationRequested();
47 if (!NativeMethods.CreateSymbolicLink(linkPath, targetPath, flags))
48 throw new Win32Exception();
49 },
50 cancellationToken,
52 TaskScheduler.Current);
53 }
54}
IIOManager that resolves paths to Environment.CurrentDirectory.
const TaskCreationOptions BlockingTaskCreationOptions
The TaskCreationOptions used to spawn Tasks for potentially long running, blocking operations.
Native methods used by the code.
CreateSymbolicLinkFlags
See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinka#param...
static bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, CreateSymbolicLinkFlags dwFlags)
See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinkw.