From 46529db0ffcc6f5590124b13d3ed7f4039dc6091 Mon Sep 17 00:00:00 2001 From: Ersan Bozduman Date: Wed, 18 Oct 2023 20:56:17 -0700 Subject: [PATCH] cleanup and expiration date adjustments --- Minio.Functional.Tests/FunctionalTest.cs | 55 ++++++++++++++---------- Minio/ApiEndpoints/BucketOperations.cs | 11 ++--- Minio/DataModel/Result/ResponseResult.cs | 2 +- Minio/Helper/OperationsHelper.cs | 3 +- Minio/RequestExtensions.cs | 4 +- 5 files changed, 38 insertions(+), 37 deletions(-) diff --git a/Minio.Functional.Tests/FunctionalTest.cs b/Minio.Functional.Tests/FunctionalTest.cs index bf14c3177..0024f3512 100644 --- a/Minio.Functional.Tests/FunctionalTest.cs +++ b/Minio.Functional.Tests/FunctionalTest.cs @@ -805,8 +805,8 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio) aesEncryption.KeySize = 256; aesEncryption.GenerateKey(); var ssec = new SSEC(aesEncryption.Key); - - using (var filestream = rsg.GenerateStreamFromSeed(6 * MB)) + Stream filestream; + await using ((filestream = rsg.GenerateStreamFromSeed(6 * MB)).ConfigureAwait(false)) { var file_write_size = filestream.Length; @@ -826,16 +826,18 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio) .WithServerSideEncryption(ssec) .WithCallbackStream(async (stream, cancellationToken) => { - using var fileStream = File.Create(tempFileName); - - await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false); - await fileStream.DisposeAsync().ConfigureAwait(false); + Stream fileStream; + await using ((fileStream = File.Create(tempFileName)).ConfigureAwait(false)) + { + await stream.CopyToAsync(fileStream, cancellationToken).ConfigureAwait(false); + await fileStream.DisposeAsync().ConfigureAwait(false); - var writtenInfo = new FileInfo(tempFileName); - file_read_size = writtenInfo.Length; + var writtenInfo = new FileInfo(tempFileName); + file_read_size = writtenInfo.Length; - Assert.AreEqual(file_write_size, file_read_size); - File.Delete(tempFileName); + Assert.AreEqual(file_write_size, file_read_size); + File.Delete(tempFileName); + } }); var statObjectArgs = new StatObjectArgs() .WithBucket(bucketName) @@ -848,24 +850,26 @@ internal static async Task PutGetStatEncryptedObject_Test2(IMinioClient minio) new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature, "Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.PASS, DateTime.Now - startTime, args: args).Log(); + File.Delete(tempFileName); + await TearDown(minio, bucketName).ConfigureAwait(false); } catch (NotImplementedException ex) { new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature, "Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.NA, DateTime.Now - startTime, "", ex.Message, ex.ToString(), args).Log(); + File.Delete(tempFileName); + await TearDown(minio, bucketName).ConfigureAwait(false); + throw; } catch (Exception ex) { new MintLogger("PutGetStatEncryptedObject_Test2", putObjectSignature, "Tests whether Put/Get/Stat multipart upload with encryption passes", TestStatus.FAIL, DateTime.Now - startTime, "", ex.Message, ex.ToString(), args).Log(); - throw; - } - finally - { File.Delete(tempFileName); await TearDown(minio, bucketName).ConfigureAwait(false); + throw; } } @@ -4871,18 +4875,20 @@ internal static async Task GetObject_3_OffsetLength_Tests(IMinioClient minio) new MintLogger(testName, getObjectSignature, "Tests whether GetObject returns all the data", TestStatus.PASS, DateTime.Now - startTime, args: args).Log(); + + if (File.Exists(tempFileName)) File.Delete(tempFileName); + if (File.Exists(tempSource)) File.Delete(tempSource); + await TearDown(minio, bucketName).ConfigureAwait(false); } catch (Exception ex) { new MintLogger(testName, getObjectSignature, "Tests whether GetObject returns all the data", TestStatus.FAIL, DateTime.Now - startTime, ex.Message, ex.ToString(), args: args).Log(); - throw; - } - finally - { + if (File.Exists(tempFileName)) File.Delete(tempFileName); if (File.Exists(tempSource)) File.Delete(tempSource); await TearDown(minio, bucketName).ConfigureAwait(false); + throw; } } } @@ -6055,11 +6061,12 @@ internal static async Task BucketLifecycleAsync_Test1(IMinioClient minio) var expDate = baseDate.AddYears(1); var exp = new Expiration(expDate); - var calculatedExpDate = expDate.AddDays(1).AddSeconds(-1).ToUniversalTime().Date; - var expInDays = (calculatedExpDate.ToLocalTime().Date - baseDate.Date).TotalDays; + var calcDateTime = DateTime.Parse(exp.ExpiryDate, null, DateTimeStyles.RoundtripKind); + var expInDays = (calcDateTime.Date - baseDate.ToUniversalTime().Date).TotalDays; - var rule1 = new LifecycleRule(null, "txt", exp, null, - new RuleFilter(null, "txt/", null), null, null, LifecycleRule.LifecycleRuleStatusEnabled); + var rule1 = new LifecycleRule(null, "txt", exp, + null, new RuleFilter(null, "txt/", null), null, + null, LifecycleRule.LifecycleRuleStatusEnabled); rules.Add(rule1); var lfc = new LifecycleConfiguration(rules); try @@ -6097,7 +6104,9 @@ internal static async Task BucketLifecycleAsync_Test1(IMinioClient minio) Assert.IsTrue(lfcObj.Rules.Count > 0); Assert.AreEqual(lfcObj.Rules.Count, lfc.Rules.Count); var lfcDate = DateTime.Parse(lfcObj.Rules[0].Expiration.ExpiryDate, null, DateTimeStyles.RoundtripKind); - Assert.AreEqual((lfcDate.Date - baseDate.Date).TotalDays, expInDays); + var lfcExpInDays = (lfcDate.Date - baseDate.ToUniversalTime().Date).TotalDays; + Assert.AreEqual(lfcExpInDays, expInDays); + new MintLogger(nameof(BucketLifecycleAsync_Test1) + ".2", getBucketLifecycleSignature, "Tests whether GetBucketLifecycleAsync passes", TestStatus.PASS, DateTime.Now - startTime, args: args) diff --git a/Minio/ApiEndpoints/BucketOperations.cs b/Minio/ApiEndpoints/BucketOperations.cs index f792b71e3..8756a5968 100644 --- a/Minio/ApiEndpoints/BucketOperations.cs +++ b/Minio/ApiEndpoints/BucketOperations.cs @@ -76,22 +76,17 @@ public async Task BucketExistsAsync(BucketExistsArgs args, CancellationTok var requestMessageBuilder = await this.CreateRequest(args).ConfigureAwait(false); using var response = await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder, - cancellationToken: cancellationToken) - .ConfigureAwait(false); + cancellationToken: cancellationToken).ConfigureAwait(false); if (response.Exception is not null && response.Exception.GetType() == typeof(BucketNotFoundException)) - { - return false; - } + return false; } catch (InternalClientException ice) { if ((ice.ServerResponse is not null && - HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode)) || + HttpStatusCode.NotFound.Equals(ice.ServerResponse.StatusCode)) || ice.ServerResponse is null) - { return false; - } } catch (Exception ex) { diff --git a/Minio/DataModel/Result/ResponseResult.cs b/Minio/DataModel/Result/ResponseResult.cs index 5f45e5c6a..0f0791d99 100644 --- a/Minio/DataModel/Result/ResponseResult.cs +++ b/Minio/DataModel/Result/ResponseResult.cs @@ -40,7 +40,7 @@ public ResponseResult(HttpRequestMessage request, Exception exception) Exception = exception; } - public Exception Exception { get; set;} + public Exception Exception { get; set; } public HttpRequestMessage Request { get; } public HttpResponseMessage Response { get; } diff --git a/Minio/Helper/OperationsHelper.cs b/Minio/Helper/OperationsHelper.cs index 544539546..81ac99369 100644 --- a/Minio/Helper/OperationsHelper.cs +++ b/Minio/Helper/OperationsHelper.cs @@ -110,8 +110,7 @@ private async Task GetObjectStreamAsync(GetObjectArgs args, CancellationToken ca var requestMessageBuilder = await this.CreateRequest(args).ConfigureAwait(false); using var response = await this.ExecuteTaskAsync(ResponseErrorHandlers, requestMessageBuilder, - cancellationToken: cancellationToken) - .ConfigureAwait(false); + cancellationToken: cancellationToken).ConfigureAwait(false); } /// diff --git a/Minio/RequestExtensions.cs b/Minio/RequestExtensions.cs index 74b47396b..827d0d44b 100644 --- a/Minio/RequestExtensions.cs +++ b/Minio/RequestExtensions.cs @@ -1,7 +1,5 @@ using System.Diagnostics.CodeAnalysis; using System.Net; -using System.Net.Http.Headers; -using Microsoft.Win32; using Minio.Credentials; using Minio.DataModel; using Minio.DataModel.Args; @@ -62,7 +60,7 @@ internal static Task ExecuteTaskAsync(this IMinioClient minioCli cancellationToken = timeoutTokenSource.Token; } - responseResult = minioClient.ExecuteWithRetry( + responseResult = minioClient.ExecuteWithRetry( async () => await minioClient.ExecuteTaskCoreAsync(errorHandlers, requestMessageBuilder, isSts, cancellationToken).ConfigureAwait(false)); }