diff --git a/src/Tgstation.Server.Host/Components/IInstanceFactory.cs b/src/Tgstation.Server.Host/Components/IInstanceFactory.cs index 8f3c7d2ab4..0c37b40778 100644 --- a/src/Tgstation.Server.Host/Components/IInstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/IInstanceFactory.cs @@ -3,6 +3,7 @@ using Microsoft.Extensions.Hosting; using Tgstation.Server.Host.Components.Interop.Bridge; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Components { @@ -18,5 +19,12 @@ namespace Tgstation.Server.Host.Components /// The . /// A resulting in a new . Task CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata); + + /// + /// Create an that resolves to the "Game" directory of the defined by . + /// + /// The . + /// The for the instance's "Game" directory. + IIOManager CreateGameIOManager(Models.Instance metadata); } } diff --git a/src/Tgstation.Server.Host/Components/InstanceFactory.cs b/src/Tgstation.Server.Host/Components/InstanceFactory.cs index 4112d1fa1b..c9b891f087 100644 --- a/src/Tgstation.Server.Host/Components/InstanceFactory.cs +++ b/src/Tgstation.Server.Host/Components/InstanceFactory.cs @@ -144,6 +144,13 @@ namespace Tgstation.Server.Host.Components /// readonly SessionConfiguration sessionConfiguration; + /// + /// Create the pointing to the "Game" directory of a given . + /// + /// The instance's . + /// The for the instance's "Game" directory. + static IIOManager CreateGameIOManager(IIOManager instanceIOManager) => new ResolvingIOManager(instanceIOManager, "Game"); + #pragma warning disable CA1502 // TODO: Decomplexify /// /// Initializes a new instance of the class. @@ -222,17 +229,32 @@ namespace Tgstation.Server.Host.Components } #pragma warning restore CA1502 + /// + public IIOManager CreateGameIOManager(Models.Instance metadata) + { + if (metadata == null) + throw new ArgumentNullException(nameof(metadata)); + + var instanceIoManager = CreateInstanceIOManager(metadata); + return CreateGameIOManager(instanceIoManager); + } + /// #pragma warning disable CA1506 // TODO: Decomplexify public async Task CreateInstance(IBridgeRegistrar bridgeRegistrar, Models.Instance metadata) { + if (bridgeRegistrar == null) + throw new ArgumentNullException(nameof(bridgeRegistrar)); + if (metadata == null) + throw new ArgumentNullException(nameof(metadata)); + // Create the ioManager for the instance - var instanceIoManager = new ResolvingIOManager(ioManager, metadata.Path); + var instanceIoManager = CreateInstanceIOManager(metadata); // various other ioManagers var repoIoManager = new ResolvingIOManager(instanceIoManager, "Repository"); var byondIOManager = new ResolvingIOManager(instanceIoManager, "Byond"); - var gameIoManager = new ResolvingIOManager(instanceIoManager, "Game"); + var gameIoManager = CreateGameIOManager(instanceIoManager); var diagnosticsIOManager = new ResolvingIOManager(instanceIoManager, "Diagnostics"); var configurationIoManager = new ResolvingIOManager(instanceIoManager, "Configuration"); @@ -386,5 +408,12 @@ namespace Tgstation.Server.Host.Components /// Test that the is functional. /// void CheckSystemCompatibility() => repositoryFactory.CreateInMemory(); + + /// + /// Create the for a given set of instance . + /// + /// The . + /// The for the . + IIOManager CreateInstanceIOManager(Models.Instance metadata) => new ResolvingIOManager(ioManager, metadata.Path); } } diff --git a/src/Tgstation.Server.Host/Components/InstanceManager.cs b/src/Tgstation.Server.Host/Components/InstanceManager.cs index 95c7546a9d..3e025b1dad 100644 --- a/src/Tgstation.Server.Host/Components/InstanceManager.cs +++ b/src/Tgstation.Server.Host/Components/InstanceManager.cs @@ -218,6 +218,8 @@ namespace Tgstation.Server.Host.Components { if (oldPath == null) throw new ArgumentNullException(nameof(oldPath)); + + using var lockContext = await SemaphoreSlimContext.Lock(instanceStateChangeSemaphore, cancellationToken); using var instanceReferenceCheck = GetInstanceReference(instance); if (instanceReferenceCheck != null) throw new InvalidOperationException("Cannot move an online instance!"); @@ -225,6 +227,10 @@ namespace Tgstation.Server.Host.Components try { await ioManager.MoveDirectory(oldPath, newPath, cancellationToken); + + // Delete the Game directory to clear out broken symlinks + var instanceGameIOManager = instanceFactory.CreateGameIOManager(instance); + await instanceGameIOManager.DeleteDirectory(".", cancellationToken); } catch (Exception ex) {