From c0e78c1a2a6e1dd01a09ae1c8b4c0aca27ab4229 Mon Sep 17 00:00:00 2001 From: Cyberboss Date: Mon, 23 Jul 2018 13:22:28 -0400 Subject: [PATCH] More cleanup and move IO stuff to it's own namespace --- src/Tgstation.Server.Host/Components/Chat/Chat.cs | 2 +- .../Components/Chat/ChatFactory.cs | 2 +- .../Components/Chat/JsonTrackingContext.cs | 1 + src/Tgstation.Server.Host/Components/Configuration.cs | 2 +- src/Tgstation.Server.Host/Components/DmbFactory.cs | 1 + src/Tgstation.Server.Host/Components/DmbProvider.cs | 2 +- src/Tgstation.Server.Host/Components/DreamMaker.cs | 1 + .../Components/InstanceFactory.cs | 1 + src/Tgstation.Server.Host/Components/Repository.cs | 2 +- .../Components/RepositoryManager.cs | 2 +- .../Components/Watchdog/SessionControllerFactory.cs | 1 + src/Tgstation.Server.Host/Core/Application.cs | 1 + .../{Core => IO}/DefaultIOManager.cs | 10 +++++++++- src/Tgstation.Server.Host/{Core => IO}/IIOManager.cs | 2 +- .../{Core => IO}/ISynchronousIOManager.cs | 2 +- .../{Core => IO}/ResolvingIOManager.cs | 2 +- .../{Core => IO}/SynchronousIOManager.cs | 2 +- src/Tgstation.Server.Host/NativeMethods.cs | 6 ++++++ src/Tgstation.Server.Host/Tgstation.Server.Host.csproj | 3 ++- 19 files changed, 33 insertions(+), 12 deletions(-) rename src/Tgstation.Server.Host/{Core => IO}/DefaultIOManager.cs (96%) rename src/Tgstation.Server.Host/{Core => IO}/IIOManager.cs (99%) rename src/Tgstation.Server.Host/{Core => IO}/ISynchronousIOManager.cs (98%) rename src/Tgstation.Server.Host/{Core => IO}/ResolvingIOManager.cs (96%) rename src/Tgstation.Server.Host/{Core => IO}/SynchronousIOManager.cs (98%) diff --git a/src/Tgstation.Server.Host/Components/Chat/Chat.cs b/src/Tgstation.Server.Host/Components/Chat/Chat.cs index 7febaa1f3b..e878aedaa3 100644 --- a/src/Tgstation.Server.Host/Components/Chat/Chat.cs +++ b/src/Tgstation.Server.Host/Components/Chat/Chat.cs @@ -8,7 +8,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Components.Chat.Providers; -using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components.Chat { diff --git a/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs b/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs index 82f5cfc72c..339664001e 100644 --- a/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs +++ b/src/Tgstation.Server.Host/Components/Chat/ChatFactory.cs @@ -1,7 +1,7 @@ using Microsoft.Extensions.Logging; using System; using Tgstation.Server.Host.Components.Chat.Commands; -using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components.Chat { diff --git a/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs b/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs index c231ea3ef7..dd552f87ff 100644 --- a/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs +++ b/src/Tgstation.Server.Host/Components/Chat/JsonTrackingContext.cs @@ -6,6 +6,7 @@ using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components.Chat { diff --git a/src/Tgstation.Server.Host/Components/Configuration.cs b/src/Tgstation.Server.Host/Components/Configuration.cs index ee163ece83..9c5a127316 100644 --- a/src/Tgstation.Server.Host/Components/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/Configuration.cs @@ -8,7 +8,7 @@ using System.Security.Cryptography; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Api.Models; -using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Security; namespace Tgstation.Server.Host.Components diff --git a/src/Tgstation.Server.Host/Components/DmbFactory.cs b/src/Tgstation.Server.Host/Components/DmbFactory.cs index 5609c3f08b..b6aed13e2b 100644 --- a/src/Tgstation.Server.Host/Components/DmbFactory.cs +++ b/src/Tgstation.Server.Host/Components/DmbFactory.cs @@ -5,6 +5,7 @@ using System.Linq; using System.Threading; using System.Threading.Tasks; using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Models; namespace Tgstation.Server.Host.Components diff --git a/src/Tgstation.Server.Host/Components/DmbProvider.cs b/src/Tgstation.Server.Host/Components/DmbProvider.cs index 4efe95cd07..d93b12ed78 100644 --- a/src/Tgstation.Server.Host/Components/DmbProvider.cs +++ b/src/Tgstation.Server.Host/Components/DmbProvider.cs @@ -1,5 +1,5 @@ using System; -using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Models; namespace Tgstation.Server.Host.Components diff --git a/src/Tgstation.Server.Host/Components/DreamMaker.cs b/src/Tgstation.Server.Host/Components/DreamMaker.cs index 4f403b2797..06cd345bf7 100644 --- a/src/Tgstation.Server.Host/Components/DreamMaker.cs +++ b/src/Tgstation.Server.Host/Components/DreamMaker.cs @@ -11,6 +11,7 @@ using Tgstation.Server.Api.Models; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Watchdog; using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components { diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 3c9466e415..6712b555e9 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -5,6 +5,7 @@ using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Components.Watchdog; using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Security; namespace Tgstation.Server.Host.Components diff --git a/src/Tgstation.Server.Host/Components/Repository.cs b/src/Tgstation.Server.Host/Components/Repository.cs index 50364ca9b1..ed5f2676d3 100644 --- a/src/Tgstation.Server.Host/Components/Repository.cs +++ b/src/Tgstation.Server.Host/Components/Repository.cs @@ -5,7 +5,7 @@ using System.Globalization; using System.Linq; using System.Threading; using System.Threading.Tasks; -using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components { diff --git a/src/Tgstation.Server.Host/Components/RepositoryManager.cs b/src/Tgstation.Server.Host/Components/RepositoryManager.cs index e87d417cbd..e18bd24820 100644 --- a/src/Tgstation.Server.Host/Components/RepositoryManager.cs +++ b/src/Tgstation.Server.Host/Components/RepositoryManager.cs @@ -2,8 +2,8 @@ using System; using System.Threading; using System.Threading.Tasks; -using Tgstation.Server.Host.Core; using Tgstation.Server.Api.Models.Internal; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components { diff --git a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs index bf472fcd33..b84535a1fa 100644 --- a/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs +++ b/src/Tgstation.Server.Host/Components/Watchdog/SessionControllerFactory.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using Tgstation.Server.Api.Models.Internal; using Tgstation.Server.Host.Components.Chat; using Tgstation.Server.Host.Core; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Security; namespace Tgstation.Server.Host.Components.Watchdog diff --git a/src/Tgstation.Server.Host/Core/Application.cs b/src/Tgstation.Server.Host/Core/Application.cs index 8040fe1464..a5bdd6196d 100644 --- a/src/Tgstation.Server.Host/Core/Application.cs +++ b/src/Tgstation.Server.Host/Core/Application.cs @@ -20,6 +20,7 @@ using Tgstation.Server.Host.Components.Chat.Commands; using Tgstation.Server.Host.Components.Watchdog; using Tgstation.Server.Host.Configuration; using Tgstation.Server.Host.Controllers; +using Tgstation.Server.Host.IO; using Tgstation.Server.Host.Models; using Tgstation.Server.Host.Security; diff --git a/src/Tgstation.Server.Host/Core/DefaultIOManager.cs b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs similarity index 96% rename from src/Tgstation.Server.Host/Core/DefaultIOManager.cs rename to src/Tgstation.Server.Host/IO/DefaultIOManager.cs index a5c3d59eb7..21cf9db515 100644 --- a/src/Tgstation.Server.Host/Core/DefaultIOManager.cs +++ b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs @@ -7,7 +7,7 @@ using System.Text; using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Core +namespace Tgstation.Server.Host.IO { /// /// that resolves paths to @@ -220,5 +220,13 @@ namespace Tgstation.Server.Host.Core } return (IReadOnlyList)results; }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); + + /// + public Task CreateSymlink(string target, string link, CancellationToken cancellationToken) => Task.Factory.StartNew(() => + { + target = ResolvePath(target); + link = ResolvePath(link); + + }, cancellationToken, TaskCreationOptions.LongRunning, TaskScheduler.Current); } } diff --git a/src/Tgstation.Server.Host/Core/IIOManager.cs b/src/Tgstation.Server.Host/IO/IIOManager.cs similarity index 99% rename from src/Tgstation.Server.Host/Core/IIOManager.cs rename to src/Tgstation.Server.Host/IO/IIOManager.cs index 69a207e692..c317e70789 100644 --- a/src/Tgstation.Server.Host/Core/IIOManager.cs +++ b/src/Tgstation.Server.Host/IO/IIOManager.cs @@ -2,7 +2,7 @@ using System.Threading; using System.Threading.Tasks; -namespace Tgstation.Server.Host.Core +namespace Tgstation.Server.Host.IO { /// /// Interface for using filesystems diff --git a/src/Tgstation.Server.Host/Core/ISynchronousIOManager.cs b/src/Tgstation.Server.Host/IO/ISynchronousIOManager.cs similarity index 98% rename from src/Tgstation.Server.Host/Core/ISynchronousIOManager.cs rename to src/Tgstation.Server.Host/IO/ISynchronousIOManager.cs index 6faa6249ad..b0d61e969b 100644 --- a/src/Tgstation.Server.Host/Core/ISynchronousIOManager.cs +++ b/src/Tgstation.Server.Host/IO/ISynchronousIOManager.cs @@ -1,7 +1,7 @@ using System.Collections.Generic; using System.Threading; -namespace Tgstation.Server.Host.Core +namespace Tgstation.Server.Host.IO { /// /// For accessing the disk in a synchronous manner diff --git a/src/Tgstation.Server.Host/Core/ResolvingIOManager.cs b/src/Tgstation.Server.Host/IO/ResolvingIOManager.cs similarity index 96% rename from src/Tgstation.Server.Host/Core/ResolvingIOManager.cs rename to src/Tgstation.Server.Host/IO/ResolvingIOManager.cs index f7d4bf2045..c10ac40b6c 100644 --- a/src/Tgstation.Server.Host/Core/ResolvingIOManager.cs +++ b/src/Tgstation.Server.Host/IO/ResolvingIOManager.cs @@ -1,7 +1,7 @@ using System; using System.IO; -namespace Tgstation.Server.Host.Core +namespace Tgstation.Server.Host.IO { /// /// An that resolve relative paths from another to a subdirectory of that diff --git a/src/Tgstation.Server.Host/Core/SynchronousIOManager.cs b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs similarity index 98% rename from src/Tgstation.Server.Host/Core/SynchronousIOManager.cs rename to src/Tgstation.Server.Host/IO/SynchronousIOManager.cs index dc56319f11..052eff0a34 100644 --- a/src/Tgstation.Server.Host/Core/SynchronousIOManager.cs +++ b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs @@ -6,7 +6,7 @@ using System.Linq; using System.Security.Cryptography; using System.Threading; -namespace Tgstation.Server.Host.Core +namespace Tgstation.Server.Host.IO { /// sealed class SynchronousIOManager : ISynchronousIOManager diff --git a/src/Tgstation.Server.Host/NativeMethods.cs b/src/Tgstation.Server.Host/NativeMethods.cs index 8a4038dc53..f68029a95b 100644 --- a/src/Tgstation.Server.Host/NativeMethods.cs +++ b/src/Tgstation.Server.Host/NativeMethods.cs @@ -13,5 +13,11 @@ namespace Tgstation.Server.Host /// [DllImport("advapi32.dll", SetLastError = true, CharSet = CharSet.Unicode)] public static extern bool LogonUser(string lpszUsername, string lpszDomain, string lpszPassword, int dwLogonType, int dwLogonProvider, out IntPtr phToken); + + /// + /// See https://docs.microsoft.com/en-us/windows/desktop/api/winbase/nf-winbase-createsymboliclinkw + /// + [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Unicode)] + static extern bool CreateSymbolicLink(string lpSymlinkFileName, string lpTargetFileName, int dwFlags); } } diff --git a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj index 02f909a7b8..662d012233 100644 --- a/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj +++ b/src/Tgstation.Server.Host/Tgstation.Server.Host.csproj @@ -33,7 +33,7 @@ - + @@ -45,6 +45,7 @@ +