Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
using SemanticBackup.Core.Helpers;
using SemanticBackup.Core.Models;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Threading;
Expand Down Expand Up @@ -46,8 +47,48 @@ await WithRetry.TaskAsync(async () =>
//Filename
string fileName = Path.GetFileName(this._backupRecord.Path);
//Proceed
using IMinioClient minioClient = new MinioClient().WithEndpoint(settings.Server, settings.Port).WithCredentials(settings.AccessKey, settings.SecretKey).WithSSL(settings.UseSsl).Build();
using IMinioClient minioClient = new MinioClient()
.WithEndpoint(settings.Server, settings.Port)
.WithCredentials(settings.AccessKey, settings.SecretKey)
.WithSSL(settings.UseSsl)
.Build();
//deleting recursive
List<Minio.DataModel.Item> objectVersions = [];
// Attempt to list object versions
ListObjectsArgs listArgs = new ListObjectsArgs()
.WithBucket(validBucket)
.WithPrefix(fileName)
.WithRecursive(true)
.WithVersions(true);

await foreach (Minio.DataModel.Item version in minioClient.ListObjectsEnumAsync(listArgs))
{
if (version.Key == fileName && !string.IsNullOrEmpty(version.VersionId))
{
objectVersions.Add(version);
}
}

if (objectVersions.Count > 0)
{
// Bucket is versioned: delete all versions
Console.WriteLine($"Found {objectVersions.Count} versions. Deleting all...");

foreach (Minio.DataModel.Item version in objectVersions)
{
await minioClient.RemoveObjectAsync(new RemoveObjectArgs()
.WithBucket(validBucket)
.WithObject(fileName)
.WithVersionId(version.VersionId), cancellationToken);

Console.WriteLine($"Deleted version {version.VersionId}");
}
}
else
{
// Bucket is non-versioned or no versions found: delete normally
Console.WriteLine("No versions found. Deleting object directly...");

await minioClient.RemoveObjectAsync(new RemoveObjectArgs()
.WithBucket(validBucket)
.WithObject(fileName), cancellationToken);
Expand Down
3 changes: 1 addition & 2 deletions SemanticBackup/Pages/Index.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Microsoft.Extensions.Logging;
using SemanticBackup.Core.Interfaces;
using System.Threading.Tasks;

namespace SemanticBackup.Pages
{
Expand All @@ -18,7 +17,7 @@ public IndexModel(ILogger<IndexModel> logger, IResourceGroupRepository resourceG
this._resourceGroupPersistance = resourceGroupPersistance;
}

public async Task<IActionResult> OnGetAsync()
public IActionResult OnGetAsync()
{
return LocalRedirect($"/resource-groups/");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,12 +148,12 @@ private async Task<IActionResult> DownloadableContentAsync(BackupRecordDelivery
new FileExtensionContentTypeProvider().TryGetContentType(BackupRecordResponse.Path, out string contentType);
contentType = contentType ?? "application/octet-stream";
string fileName = System.IO.Path.GetFileName(BackupRecordResponse.Path);
var cd = new System.Net.Mime.ContentDisposition
System.Net.Mime.ContentDisposition cd = new()
{
FileName = fileName,
Inline = true,
};
Response.Headers.Add("Content-Disposition", cd.ToString());
Response.Headers.TryAdd("Content-Disposition", cd.ToString());
byte[] filedata = await System.IO.File.ReadAllBytesAsync(BackupRecordResponse.Path);
return File(filedata, contentType);
}
Expand Down
4 changes: 2 additions & 2 deletions SemanticBackup/SemanticBackup.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@
<TargetFramework>net8.0</TargetFramework>
<UserSecretsId>98e83838-8ab0-44d3-a023-52d80ba01705</UserSecretsId>
<DockerDefaultTargetOS>Linux</DockerDefaultTargetOS>
<AssemblyVersion>5.2.1.3</AssemblyVersion>
<FileVersion>5.2.1.3</FileVersion>
<AssemblyVersion>5.2.1.4</AssemblyVersion>
<FileVersion>5.2.1.4</FileVersion>
</PropertyGroup>

<ItemGroup>
Expand Down