tgstation-server 6.12.0
The /tg/station 13 server suite
Loading...
Searching...
No Matches
WindowsFilesystemLinkFactory.cs
Go to the documentation of this file.
1using System;
2using System.ComponentModel;
3using System.IO;
4using System.Threading;
5using System.Threading.Tasks;
6
8
10{
15 {
18
20 public Task CreateHardLink(string targetPath, string linkPath, CancellationToken cancellationToken)
21 => throw new NotSupportedException();
22
24 public Task CreateSymbolicLink(string targetPath, string linkPath, CancellationToken cancellationToken) => Task.Factory.StartNew(
25 () =>
26 {
27 ArgumentNullException.ThrowIfNull(targetPath);
28 ArgumentNullException.ThrowIfNull(linkPath);
29
30 // check if its not a file
31 var flags = File.Exists(targetPath) ? NativeMethods.CreateSymbolicLinkFlags.None : NativeMethods.CreateSymbolicLinkFlags.Directory;
32
33 /*
34 * no don't fucking use this
35 * sure it works in SOME cases
36 * i.e. win10 1803+ and IN DEVELOPER MODE
37 * other times it throws ERROR_INVALID_PARAMETER
38 * but the fucking worst is there are some configurations of windows that accept the argument and allow the function to succeed
39 * BUT IT DOESN'T CREATE THE FUCKING LINK
40 * I AM NOT DEBUGGING THAT SHIT AGAIN AHHH
41
42 flags |= NativeMethods.CreateSymbolicLinkFlags.AllowUnprivilegedCreate;
43 */
44
45 cancellationToken.ThrowIfCancellationRequested();
46 if (!NativeMethods.CreateSymbolicLink(linkPath, targetPath, flags))
47 throw new Win32Exception();
48 },
49 cancellationToken,
51 TaskScheduler.Current);
52 }
53}
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.