From 3a6dfa8936cb563e6f93b4c308894bbcbda458ae Mon Sep 17 00:00:00 2001 From: Dominion Date: Fri, 9 Jun 2023 13:23:37 -0400 Subject: [PATCH] Make IFileStreamProvider more generic - Move SetError up to IFileUploadTicket. - Move from Transfer to IO namespace. --- .../IO/DelayedFileDownloader.cs | 9 --------- .../{Transfer => IO}/IFileStreamProvider.cs | 15 +++------------ .../Transfer/IFileUploadTicket.cs | 11 ++++++++++- .../IO/TestDelayedFileDownloader.cs | 3 --- 4 files changed, 13 insertions(+), 25 deletions(-) rename src/Tgstation.Server.Host/{Transfer => IO}/IFileStreamProvider.cs (53%) diff --git a/src/Tgstation.Server.Host/IO/DelayedFileDownloader.cs b/src/Tgstation.Server.Host/IO/DelayedFileDownloader.cs index 0e04b8e94e..38908efa6f 100644 --- a/src/Tgstation.Server.Host/IO/DelayedFileDownloader.cs +++ b/src/Tgstation.Server.Host/IO/DelayedFileDownloader.cs @@ -3,9 +3,6 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using Tgstation.Server.Api.Models; -using Tgstation.Server.Host.Transfer; - namespace Tgstation.Server.Host.IO { /// @@ -98,11 +95,5 @@ namespace Tgstation.Server.Host.IO return await localTask; } } - - /// - public void SetError(ErrorCode errorCode, string additionalData) - { - // no-op - } } } diff --git a/src/Tgstation.Server.Host/Transfer/IFileStreamProvider.cs b/src/Tgstation.Server.Host/IO/IFileStreamProvider.cs similarity index 53% rename from src/Tgstation.Server.Host/Transfer/IFileStreamProvider.cs rename to src/Tgstation.Server.Host/IO/IFileStreamProvider.cs index 84a594f298..c2e70eae8c 100644 --- a/src/Tgstation.Server.Host/Transfer/IFileStreamProvider.cs +++ b/src/Tgstation.Server.Host/IO/IFileStreamProvider.cs @@ -3,9 +3,7 @@ using System.IO; using System.Threading; using System.Threading.Tasks; -using Tgstation.Server.Api.Models; - -namespace Tgstation.Server.Host.Transfer +namespace Tgstation.Server.Host.IO { /// /// Interface for asynchronously consuming s of files. @@ -16,15 +14,8 @@ namespace Tgstation.Server.Host.Transfer /// Gets the for the file to consume. May be called multiple times, though cancelling any may cause all calls to be cancelled. All calls yield the same reference. /// /// The for the operation. - /// A resulting in the uploaded of the file on success, if the file could not be provider. - /// The resulting is owned by the and is short lived. It should be buffered if it needs use outside the lifetime of the . + /// A resulting in the uploaded of the file on success, if it could not be provided. + /// The resulting is owned by the and is short lived unless otherwise specified. It should be buffered if it needs use outside the lifetime of the . Task GetResult(CancellationToken cancellationToken); - - /// - /// Sets an that indicates why the consuming operation could not complete. May only be called once on a . - /// - /// The to set. - /// Any additional information that can be provided about the error. - void SetError(ErrorCode errorCode, string additionalData); } } diff --git a/src/Tgstation.Server.Host/Transfer/IFileUploadTicket.cs b/src/Tgstation.Server.Host/Transfer/IFileUploadTicket.cs index f11da1dd58..c1bd6e5725 100644 --- a/src/Tgstation.Server.Host/Transfer/IFileUploadTicket.cs +++ b/src/Tgstation.Server.Host/Transfer/IFileUploadTicket.cs @@ -1,4 +1,6 @@ -using Tgstation.Server.Api.Models.Response; +using Tgstation.Server.Api.Models; +using Tgstation.Server.Api.Models.Response; +using Tgstation.Server.Host.IO; namespace Tgstation.Server.Host.Transfer { @@ -11,5 +13,12 @@ namespace Tgstation.Server.Host.Transfer /// The . /// FileTicketResponse Ticket { get; } + + /// + /// Sets an that indicates why the consuming operation could not complete. May only be called once on a . + /// + /// The to set. + /// Any additional information that can be provided about the error. + void SetError(ErrorCode errorCode, string additionalData); } } diff --git a/tests/Tgstation.Server.Host.Tests/IO/TestDelayedFileDownloader.cs b/tests/Tgstation.Server.Host.Tests/IO/TestDelayedFileDownloader.cs index a72f57aa07..cb97af45c8 100644 --- a/tests/Tgstation.Server.Host.Tests/IO/TestDelayedFileDownloader.cs +++ b/tests/Tgstation.Server.Host.Tests/IO/TestDelayedFileDownloader.cs @@ -99,9 +99,6 @@ namespace Tgstation.Server.Host.IO.Tests await Assert.ThrowsExceptionAsync(() => task2); await Assert.ThrowsExceptionAsync(() => task3); - // code coverage - downloader.SetError(ErrorCode.BadHeaders, null); - mockFileDownloader.VerifyAll(); } }