From b4a32e1aaf047cf647ac3ddad188d2675a6505d0 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 2 Apr 2023 12:50:07 -0400 Subject: [PATCH 1/5] Fix Directory deletion not working --- src/Tgstation.Server.Host/IO/DefaultIOManager.cs | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) 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); } From 775f1c1e8f5d7493232381d30094141ef175d2e6 Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 2 Apr 2023 12:50:23 -0400 Subject: [PATCH 2/5] Add some IIOManager tests --- .../IO/TestIOManager.cs | 55 +++++++++++++++++++ 1 file changed, 55 insertions(+) create mode 100644 tests/Tgstation.Server.Host.Tests/IO/TestIOManager.cs 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; + } + } + } +} From d1e6e0354460f816c9553045c03c8d654f231b0d Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 2 Apr 2023 12:50:40 -0400 Subject: [PATCH 3/5] Add GameStaticFiles directory to integration test --- tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs b/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs index 35462a80cc..45307a22f3 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; From a5a8f9a2ab8542c45825c732280673d4b95fc9cc Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 2 Apr 2023 12:51:06 -0400 Subject: [PATCH 4/5] Version bump to 5.7.2 --- build/Version.props | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 From b869d9f4998b0b3bb4c62926849247fdb0976c2f Mon Sep 17 00:00:00 2001 From: Dominion Date: Sun, 2 Apr 2023 12:54:48 -0400 Subject: [PATCH 5/5] Actually implement the config test, dear god. --- .../Tgstation.Server.Tests/Instance/ConfigurationTest.cs | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs b/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs index 45307a22f3..05227e7328 100644 --- a/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs +++ b/tests/Tgstation.Server.Tests/Instance/ConfigurationTest.cs @@ -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)