diff --git a/build/Version.props b/build/Version.props index 1379ffd94e..e58434a58c 100644 --- a/build/Version.props +++ b/build/Version.props @@ -3,7 +3,7 @@ - 5.7.1 + 5.7.2 4.4.0 9.9.0 10.3.0 diff --git a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs index ec1dc01c05..485865877b 100644 --- a/src/Tgstation.Server.Host/IO/DefaultIOManager.cs +++ b/src/Tgstation.Server.Host/IO/DefaultIOManager.cs @@ -41,9 +41,10 @@ namespace Tgstation.Server.Host.IO /// /// of the directory to empty. /// The for the operation. - /// A representing the running operation. - static async Task NormalizeAndDelete(DirectoryInfo dir, CancellationToken cancellationToken) + static void NormalizeAndDelete(DirectoryInfo dir, CancellationToken cancellationToken) { + cancellationToken.ThrowIfCancellationRequested(); + // check if we are a symbolic link if (!dir.Attributes.HasFlag(FileAttributes.Directory) || dir.Attributes.HasFlag(FileAttributes.ReparsePoint)) { @@ -51,14 +52,8 @@ namespace Tgstation.Server.Host.IO return; } - await Task.Yield(); - - var tasks = new List(); foreach (var subDir in dir.EnumerateDirectories()) - { - cancellationToken.ThrowIfCancellationRequested(); - tasks.Add(NormalizeAndDelete(subDir, cancellationToken)); - } + NormalizeAndDelete(subDir, cancellationToken); foreach (var file in dir.EnumerateFiles()) { @@ -67,7 +62,6 @@ namespace Tgstation.Server.Host.IO file.Delete(); } - await Task.WhenAll(tasks); cancellationToken.ThrowIfCancellationRequested(); dir.Delete(true); } @@ -158,7 +152,7 @@ namespace Tgstation.Server.Host.IO return Task.Factory.StartNew( () => NormalizeAndDelete(di, cancellationToken), cancellationToken, - BlockingTaskCreationOptions, + TaskCreationOptions.LongRunning, TaskScheduler.Current); } diff --git a/tests/Tgstation.Server.Host.Tests/IO/TestIOManager.cs b/tests/Tgstation.Server.Host.Tests/IO/TestIOManager.cs new file mode 100644 index 0000000000..3f978cd983 --- /dev/null +++ b/tests/Tgstation.Server.Host.Tests/IO/TestIOManager.cs @@ -0,0 +1,55 @@ +using Microsoft.VisualStudio.TestTools.UnitTesting; + +using System.IO; +using System.Threading.Tasks; + +using Tgstation.Server.Host.System; + +namespace Tgstation.Server.Host.IO.Tests +{ + [TestClass] + public sealed class TestIOManager + { + readonly IIOManager ioManager = new DefaultIOManager(new AssemblyInformationProvider()); + + [TestMethod] + public async Task TestDeleteDirectory() + { + var tempPath = Path.GetTempFileName(); + File.Delete(tempPath); + Directory.CreateDirectory(tempPath); + try + { + await ioManager.DeleteDirectory(tempPath, default); + + Assert.IsFalse(Directory.Exists(tempPath)); + } + catch + { + Directory.Delete(tempPath); + throw; + } + } + + [TestMethod] + public async Task TestDirectoryExists() + { + var tempPath = Path.GetTempFileName(); + File.Delete(tempPath); + + Assert.IsFalse(await ioManager.DirectoryExists(tempPath, default)); + + Directory.CreateDirectory(tempPath); + + try + { + Assert.IsTrue(await ioManager.DirectoryExists(tempPath, default)); + } + catch + { + Directory.Delete(tempPath); + throw; + } + } + } +} diff --git a/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs b/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs index 35462a80cc..05227e7328 100644 --- a/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using System.Net.Http; using System.Net.Mime; @@ -87,6 +87,14 @@ namespace Tgstation.Server.Tests.Instance var tmp = (TestDir.Path?.StartsWith('/') ?? false) ? '.' + TestDir.Path : TestDir.Path; var path = Path.Combine(instance.Path, "Configuration", tmp); Assert.IsFalse(Directory.Exists(path)); + + // leave a directory there to test the deployment process + var staticDir = new ConfigurationFileRequest + { + Path = "/GameStaticFiles/data" + }; + + await configurationClient.CreateDirectory(staticDir, cancellationToken); } public async Task Run(CancellationToken cancellationToken)