Merge pull request #1446 from tgstation/HowEmbarrasing [TGSDeploy]

How embarrasing
This commit is contained in:
Jordan Dominion
2023-04-02 12:55:20 -04:00
committed by GitHub
4 changed files with 70 additions and 13 deletions
+1 -1
View File
@@ -3,7 +3,7 @@
<!-- Integration tests will ensure they match across the board -->
<Import Project="ControlPanelVersion.props" />
<PropertyGroup>
<TgsCoreVersion>5.7.1</TgsCoreVersion>
<TgsCoreVersion>5.7.2</TgsCoreVersion>
<TgsConfigVersion>4.4.0</TgsConfigVersion>
<TgsApiVersion>9.9.0</TgsApiVersion>
<TgsApiLibraryVersion>10.3.0</TgsApiLibraryVersion>
@@ -41,9 +41,10 @@ namespace Tgstation.Server.Host.IO
/// </summary>
/// <param name="dir"><see cref="DirectoryInfo"/> of the directory to empty.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task"/> representing the running operation.</returns>
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<Task>();
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);
}
@@ -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;
}
}
}
}
@@ -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)