tgstation-server 6.19.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.Abstractions;
4using System.Threading;
5using System.Threading.Tasks;
6
8
10{
15 {
18
22 readonly IFileSystem fileSystem;
23
29 {
30 this.fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
31 }
32
34 public Task CreateHardLink(string targetPath, string linkPath, CancellationToken cancellationToken)
35 => throw new NotSupportedException();
36
38 public Task CreateSymbolicLink(string targetPath, string linkPath, CancellationToken cancellationToken) => Task.Factory.StartNew(
39 () =>
40 {
41 ArgumentNullException.ThrowIfNull(targetPath);
42 ArgumentNullException.ThrowIfNull(linkPath);
43
44 // check if its not a file
45 var flags = fileSystem.File.Exists(targetPath) ? NativeMethods.CreateSymbolicLinkFlags.None : NativeMethods.CreateSymbolicLinkFlags.Directory;
46
47 /*
48 * no don't fucking use this
49 * sure it works in SOME cases
50 * i.e. win10 1803+ and IN DEVELOPER MODE
51 * other times it throws ERROR_INVALID_PARAMETER
52 * but the fucking worst is there are some configurations of windows that accept the argument and allow the function to succeed
53 * BUT IT DOESN'T CREATE THE FUCKING LINK
54 * I AM NOT DEBUGGING THAT SHIT AGAIN AHHH
55
56 flags |= NativeMethods.CreateSymbolicLinkFlags.AllowUnprivilegedCreate;
57 */
58
59 cancellationToken.ThrowIfCancellationRequested();
60 if (!NativeMethods.CreateSymbolicLink(linkPath, targetPath, flags))
61 throw new Win32Exception();
62 },
63 cancellationToken,
65 TaskScheduler.Current);
66 }
67}
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.