diff --git a/build/Version.props b/build/Version.props index dc59a0b959f..f6e5331f590 100644 --- a/build/Version.props +++ b/build/Version.props @@ -3,7 +3,7 @@ - 6.11.1 + 6.11.2 5.3.0 10.10.0 0.2.0 diff --git a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs index 86ae2c28ca8..93e1a0b9193 100644 --- a/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs +++ b/src/Tgstation.Server.Host/Components/StaticFiles/Configuration.cs @@ -463,6 +463,8 @@ await ValueTaskExtensions.WhenAll(entries.Select(async file = await EnsureDirectories(cancellationToken); var path = ValidateConfigRelativePath(configurationRelativePath); + logger.LogTrace("Starting write to {path}", path); + ConfigurationFileResponse? result = null; void WriteImpl() @@ -476,14 +478,21 @@ async Task UploadHandler() await using (fileTicket) { var fileHash = previousHash; + logger.LogTrace("Write to {path} waiting for upload stream", path); var uploadStream = await fileTicket.GetResult(uploadCancellationToken); if (uploadStream == null) + { + logger.LogTrace("Write to {path} expired", path); return; // expired + } + logger.LogTrace("Write to {path} received stream of length {length}...", path, uploadStream.Length); bool success = false; void WriteCallback() { + logger.LogTrace("Running synchronous write..."); success = synchronousIOManager.WriteFileChecked(path, uploadStream, ref fileHash, cancellationToken); + logger.LogTrace("Finished write {un}successfully!", success ? String.Empty : "un"); } if (fileTicket == null) diff --git a/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs index 4dbf3d833bf..b0388b51af9 100644 --- a/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs +++ b/src/Tgstation.Server.Host/IO/SynchronousIOManager.cs @@ -6,11 +6,27 @@ using System.Security.Cryptography; using System.Threading; +using Microsoft.Extensions.Logging; + namespace Tgstation.Server.Host.IO { /// sealed class SynchronousIOManager : ISynchronousIOManager { + /// + /// The for the . + /// + readonly ILogger logger; + + /// + /// Initializes a new instance of the class. + /// + /// The value of . + public SynchronousIOManager(ILogger logger) + { + this.logger = logger ?? throw new ArgumentNullException(nameof(logger)); + } + /// public bool CreateDirectory(string path, CancellationToken cancellationToken) { @@ -85,13 +101,18 @@ public bool WriteFileChecked(string path, Stream data, ref string? sha1InOut, Ca cancellationToken.ThrowIfCancellationRequested(); + logger.LogTrace("Starting checked write to {path} ({fileType} file)", path, newFile ? "New" : "Pre-existing"); + using (var file = File.Open(path, FileMode.OpenOrCreate, FileAccess.ReadWrite, FileShare.None)) { cancellationToken.ThrowIfCancellationRequested(); // no sha1? no write if (file.Length != 0 && sha1InOut == null) + { + logger.LogDebug("Aborting checked write due to missing SHA!"); return false; + } // suppressed due to only using for consistency checks using (var sha1 = SHA1.Create()) @@ -109,6 +130,10 @@ public bool WriteFileChecked(string path, Stream data, ref string? sha1InOut, Ca } var originalSha1 = GetSha1(file); + + if (!newFile) + logger.LogTrace("Existing SHA calculated to be {sha}", originalSha1); + if (originalSha1 != sha1InOut && !(newFile && sha1InOut == null)) { sha1InOut = originalSha1; @@ -122,6 +147,7 @@ public bool WriteFileChecked(string path, Stream data, ref string? sha1InOut, Ca if (data.Length != 0) { + logger.LogDebug("Writing file of length {size}", data.Length); file.Seek(0, SeekOrigin.Begin); data.Seek(0, SeekOrigin.Begin); @@ -132,7 +158,11 @@ public bool WriteFileChecked(string path, Stream data, ref string? sha1InOut, Ca } if (data.Length == 0) + { + logger.LogDebug("Stream is empty, deleting file"); File.Delete(path); + } + return true; } } diff --git a/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs b/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs index ff3bd0b5b83..6df0a9e5738 100644 --- a/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs +++ b/tests/Tgstation.Server.Host.Tests/Components/StaticFiles/TestConfiguration.cs @@ -46,7 +46,7 @@ public async Task TestListOrdering() var configuration = new Configuration( ioManager, - new SynchronousIOManager(), + new SynchronousIOManager(loggerFactory.CreateLogger()), Mock.Of(), Mock.Of(), Mock.Of(),