Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into 2-minio-dotnet-remo…
Browse files Browse the repository at this point in the history
…veIncompleteUploads
  • Loading branch information
BigUstad committed Nov 28, 2020
2 parents 7ee3235 + 663fb74 commit a61432f
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 8 deletions.
32 changes: 26 additions & 6 deletions Minio/ApiEndpoints/ObjectOperations.cs
Original file line number Diff line number Diff line change
Expand Up @@ -754,14 +754,34 @@ private async Task<string> PutObjectAsync(string bucketName, string objectName,
/// <returns></returns>
public async Task RemoveIncompleteUploadAsync(string bucketName, string objectName, CancellationToken cancellationToken = default(CancellationToken))
{
var uploads = await this.ListIncompleteUploads(bucketName, objectName, cancellationToken: cancellationToken).ToArray();
foreach (Upload upload in uploads)
{
if (objectName == upload.Key)
ListIncompleteUploadsArgs listArgs = new ListIncompleteUploadsArgs()
.WithBucket(bucketName)
.WithPrefix(objectName);
IObservable<Upload> observable = this.ListIncompleteUploads(listArgs, cancellationToken: cancellationToken);

IDisposable subscription = observable.Subscribe(
async upload =>
{
try
{
if (objectName == upload.Key)
{
await this.RemoveUploadAsync(bucketName, objectName, upload.UploadId, cancellationToken).ConfigureAwait(false);
}
}
catch(Exception ex)
{
if (ex.GetType() != typeof(BucketNotFoundException)) // Ignoring bucket not found as upload is deleted as desired
{
throw ex;
}
}
},
ex =>
{
await this.RemoveUploadAsync(bucketName, objectName, upload.UploadId, cancellationToken).ConfigureAwait(false);
throw ex;
}
}
);
}

/// <summary>
Expand Down
6 changes: 4 additions & 2 deletions Minio/DataModel/ObjectOperationsResponse.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

using System;
using System.Collections.Generic;
using System.Globalization;
using System.Xml.Linq;
using System.IO;
using System.Linq;
using System.Net;
Expand All @@ -25,6 +25,7 @@
using RestSharp;

using Minio.DataModel;
using System.Xml.Serialization;

namespace Minio
{
Expand All @@ -39,6 +40,7 @@ internal SelectObjectContentResponse(HttpStatusCode statusCode, string responseC

}


internal class StatObjectResponse : GenericResponse
{
internal ObjectStat ObjectInfo { get; set; }
Expand Down Expand Up @@ -77,4 +79,4 @@ internal GetMultipartUploadsListResponse(HttpStatusCode statusCode, string respo
this.UploadResult = new Tuple<ListMultipartUploadsResult, List<Upload>>(uploadsResult, uploads.ToList());
}
}
}
}

0 comments on commit a61432f

Please sign in to comment.