Skip to content

Commit 2387eaa

Browse files
martijn00Ersan Bozduman
andauthored
Fix analyzer update (#974)
* Fix analyzer update * Fixes * Cleanup double callback * fixes lint changes * cleans up the rebase conflict * more clean up --------- Co-authored-by: Ersan Bozduman <ersanbozduman@gmail.com>
1 parent 71d5f5d commit 2387eaa

File tree

9 files changed

+32
-20
lines changed

9 files changed

+32
-20
lines changed

Minio.Functional.Tests/FunctionalTest.cs

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -594,8 +594,7 @@ internal static async Task TearDown(IMinioClient minio, string bucketName)
594594
ObjectLockConfiguration lockConfig = null;
595595
try
596596
{
597-
VersioningConfiguration versioningConfig = null;
598-
versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
597+
var versioningConfig = await minio.GetVersioningAsync(new GetVersioningArgs()
599598
.WithBucket(bucketName)
600599
.WithVersions(true)).ConfigureAwait(false);
601600
if (versioningConfig is not null &&
@@ -831,7 +830,7 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio)
831830
.WithServerSideEncryption(ssec)
832831
.WithCallbackStream(async (stream, cancellationToken) =>
833832
{
834-
Stream fileStream;
833+
FileStream fileStream;
835834
await using ((fileStream = File.Create(tempFileName)).ConfigureAwait(false))
836835
{
837836
await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false);

Minio.Tests/ReuseTcpConnectionTest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ private async Task<double> GetObjectLength(string bucket, string objectName)
8989
var getObjectArgs = new GetObjectArgs()
9090
.WithBucket(bucket)
9191
.WithObject(objectName)
92-
.WithCallbackStream(stream => stream.Dispose());
92+
.WithCallbackStream(async (stream, _) => await stream.DisposeAsync().ConfigureAwait(false));
9393
_ = await minioClient.GetObjectAsync(getObjectArgs).ConfigureAwait(false);
9494

9595
return objectLength;

Minio/DataModel/Args/GetObjectArgs.cs

Lines changed: 23 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,7 @@ public GetObjectArgs()
2828
OffsetLengthSet = false;
2929
}
3030

31-
internal Action<Stream> CallBack { get; private set; }
32-
internal Func<Stream, CancellationToken, Task> FuncCallBack { get; private set; }
31+
internal Func<Stream, CancellationToken, Task> CallBack { get; private set; }
3332
internal long ObjectOffset { get; private set; }
3433
internal long ObjectLength { get; private set; }
3534
internal string FileName { get; private set; }
@@ -38,7 +37,7 @@ public GetObjectArgs()
3837
internal override void Validate()
3938
{
4039
base.Validate();
41-
if (CallBack is null && FuncCallBack is null && string.IsNullOrEmpty(FileName))
40+
if (CallBack is null && string.IsNullOrEmpty(FileName))
4241
throw new MinioException("Atleast one of " + nameof(CallBack) + ", CallBack method or " + nameof(FileName) +
4342
" file path to save need to be set for GetObject operation.");
4443

@@ -76,8 +75,7 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild
7675
{
7776
if (!string.IsNullOrEmpty(VersionId)) requestMessageBuilder.AddQueryParameter("versionId", $"{VersionId}");
7877

79-
if (CallBack is not null) requestMessageBuilder.ResponseWriter = CallBack;
80-
else requestMessageBuilder.FunctionResponseWriter = FuncCallBack;
78+
requestMessageBuilder.ResponseWriter = CallBack;
8179

8280
if (Headers.TryGetValue(S3ZipExtractKey, out var value))
8381
requestMessageBuilder.AddQueryParameter(S3ZipExtractKey, value);
@@ -87,13 +85,31 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild
8785

8886
public GetObjectArgs WithCallbackStream(Action<Stream> cb)
8987
{
90-
CallBack = cb;
88+
CallBack = (stream, cancellationToken) =>
89+
{
90+
var taskCompletionSource = new TaskCompletionSource<bool>();
91+
92+
if (cancellationToken.IsCancellationRequested)
93+
taskCompletionSource.SetCanceled();
94+
else
95+
try
96+
{
97+
cb(stream);
98+
taskCompletionSource.SetResult(true);
99+
}
100+
catch (Exception ex)
101+
{
102+
taskCompletionSource.SetException(ex);
103+
}
104+
105+
return taskCompletionSource.Task;
106+
};
91107
return this;
92108
}
93109

94110
public GetObjectArgs WithCallbackStream(Func<Stream, CancellationToken, Task> cb)
95111
{
96-
FuncCallBack = cb;
112+
CallBack = cb;
97113
return this;
98114
}
99115

Minio/DataModel/Args/ListenBucketNotificationsArgs.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ internal override HttpRequestMessageBuilder BuildRequest(HttpRequestMessageBuild
7171
requestMessageBuilder.AddQueryParameter("prefix", Prefix);
7272
requestMessageBuilder.AddQueryParameter("suffix", Suffix);
7373

74-
requestMessageBuilder.FunctionResponseWriter = async (responseStream, cancellationToken) =>
74+
requestMessageBuilder.ResponseWriter = async (responseStream, cancellationToken) =>
7575
{
7676
using var sr = new StreamReader(responseStream);
7777
while (!sr.EndOfStream)

Minio/DataModel/DeleteObjectsRequest.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2017 MinIO, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");

Minio/DataModel/Replication/AndOperator.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
/*
1+
/*
22
* MinIO .NET Library for Amazon S3 Compatible Cloud Storage, (C) 2021 MinIO, Inc.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");

Minio/HttpRequestMessageBuilder.cs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,8 +51,7 @@ public HttpRequestMessageBuilder(HttpMethod method, Uri requestUri)
5151
}
5252

5353
public Uri RequestUri { get; set; }
54-
public Action<Stream> ResponseWriter { get; set; }
55-
public Func<Stream, CancellationToken, Task> FunctionResponseWriter { get; set; }
54+
public Func<Stream, CancellationToken, Task> ResponseWriter { get; set; }
5655
public HttpMethod Method { get; }
5756

5857
public HttpRequestMessage Request

Minio/MinioClientExtensions.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public static IMinioClient WithEndpoint(this IMinioClient minioClient, string en
5959
{
6060
if (minioClient is null) throw new ArgumentNullException(nameof(minioClient));
6161

62-
if (port < 1 || port > 65535)
62+
if (port is < 1 or > 65535)
6363
throw new ArgumentException(
6464
string.Format(CultureInfo.InvariantCulture, "Port {0} is not a number between 1 and 65535", port),
6565
nameof(port));

Minio/RequestExtensions.cs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -98,9 +98,7 @@ private static async Task<ResponseResult> ExecuteTaskCoreAsync(this IMinioClient
9898
.ConfigureAwait(false);
9999
responseResult = new ResponseResult(request, response);
100100
if (requestMessageBuilder.ResponseWriter is not null)
101-
requestMessageBuilder.ResponseWriter(responseResult.ContentStream);
102-
if (requestMessageBuilder.FunctionResponseWriter is not null)
103-
await requestMessageBuilder.FunctionResponseWriter(responseResult.ContentStream, cancellationToken)
101+
await requestMessageBuilder.ResponseWriter(responseResult.ContentStream, cancellationToken)
104102
.ConfigureAwait(false);
105103

106104
var path = request.RequestUri.LocalPath.TrimStart('/').TrimEnd('/').Split('/');

0 commit comments

Comments
 (0)