Nullify FileUploadProvider

This commit is contained in:
Jordan Dominion
2023-11-24 10:02:07 -05:00
parent dffe0d1d08
commit 774315d3fd
@@ -9,8 +9,6 @@ using Tgstation.Server.Api.Models;
using Tgstation.Server.Api.Models.Response;
using Tgstation.Server.Host.IO;
#nullable disable
namespace Tgstation.Server.Host.Transfer
{
/// <inheritdoc />
@@ -27,7 +25,7 @@ namespace Tgstation.Server.Host.Transfer
/// <summary>
/// The <see cref="TaskCompletionSource{TResult}"/> for the <see cref="Stream"/>.
/// </summary>
readonly TaskCompletionSource<Stream> streamTcs;
readonly TaskCompletionSource<Stream?> streamTcs;
/// <summary>
/// The <see cref="TaskCompletionSource"/> that completes in <see cref="IDisposable.Dispose"/> or when <see cref="SetError(ErrorCode, string)"/> is called.
@@ -42,7 +40,7 @@ namespace Tgstation.Server.Host.Transfer
/// <summary>
/// The <see cref="ErrorMessageResponse"/> that occurred while processing the upload if any.
/// </summary>
ErrorMessageResponse errorMessage;
ErrorMessageResponse? errorMessage;
/// <summary>
/// Initializes a new instance of the <see cref="FileUploadProvider"/> class.
@@ -54,7 +52,7 @@ namespace Tgstation.Server.Host.Transfer
Ticket = ticket ?? throw new ArgumentNullException(nameof(ticket));
ticketExpiryCts = new CancellationTokenSource();
streamTcs = new TaskCompletionSource<Stream>();
streamTcs = new TaskCompletionSource<Stream?>();
completionTcs = new TaskCompletionSource();
this.streamKind = streamKind;
}
@@ -68,7 +66,7 @@ namespace Tgstation.Server.Host.Transfer
}
/// <inheritdoc />
public async ValueTask<Stream> GetResult(CancellationToken cancellationToken)
public async ValueTask<Stream?> GetResult(CancellationToken cancellationToken)
{
using (cancellationToken.Register(() => streamTcs.TrySetCanceled(cancellationToken)))
using (ticketExpiryCts.Token.Register(() => streamTcs.TrySetResult(null)))
@@ -90,14 +88,14 @@ namespace Tgstation.Server.Host.Transfer
/// <param name="stream">The <see cref="Stream"/> containing uploaded data.</param>
/// <param name="cancellationToken">The <see cref="CancellationToken"/> for the operation.</param>
/// <returns>A <see cref="Task{TResult}"/> resulting in <see langword="null"/>, <see cref="ErrorMessageResponse"/> otherwise.</returns>
public async ValueTask<ErrorMessageResponse> Completion(Stream stream, CancellationToken cancellationToken)
public async ValueTask<ErrorMessageResponse?> Completion(Stream stream, CancellationToken cancellationToken)
{
ArgumentNullException.ThrowIfNull(stream);
if (ticketExpiryCts.IsCancellationRequested)
return new ErrorMessageResponse(ErrorCode.ResourceNotPresent);
Stream bufferedStream = null;
Stream? bufferedStream = null;
try
{
switch (streamKind)