🐛 Fix some bugs that introduced in previous changes
This commit is contained in:
@@ -45,43 +45,39 @@ public class FileObjectCleanupJob(AppDatabase db, FileService fileService, ILogg
|
||||
.Where(r => r.ObjectId == fileObject.Id)
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var replica in replicas)
|
||||
foreach (var replica in replicas.Where(r => r.PoolId.HasValue))
|
||||
{
|
||||
var dest = await fileService.GetRemoteStorageConfig(replica.PoolId);
|
||||
if (dest != null)
|
||||
var dest = await fileService.GetRemoteStorageConfig(replica.PoolId!.Value);
|
||||
if (dest == null) continue;
|
||||
var client = fileService.CreateMinioClient(dest);
|
||||
if (client == null) continue;
|
||||
try
|
||||
{
|
||||
var client = fileService.CreateMinioClient(dest);
|
||||
if (client != null)
|
||||
await client.RemoveObjectAsync(
|
||||
new RemoveObjectArgs()
|
||||
.WithBucket(dest.Bucket)
|
||||
.WithObject(replica.StorageId)
|
||||
);
|
||||
if (fileObject.HasCompression)
|
||||
{
|
||||
try
|
||||
{
|
||||
await client.RemoveObjectAsync(
|
||||
new RemoveObjectArgs()
|
||||
.WithBucket(dest.Bucket)
|
||||
.WithObject(replica.StorageId)
|
||||
);
|
||||
if (fileObject.HasCompression)
|
||||
{
|
||||
await client.RemoveObjectAsync(
|
||||
new RemoveObjectArgs()
|
||||
.WithBucket(dest.Bucket)
|
||||
.WithObject(replica.StorageId + ".compressed")
|
||||
);
|
||||
}
|
||||
if (fileObject.HasThumbnail)
|
||||
{
|
||||
await client.RemoveObjectAsync(
|
||||
new RemoveObjectArgs()
|
||||
.WithBucket(dest.Bucket)
|
||||
.WithObject(replica.StorageId + ".thumbnail")
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete orphaned file object {ObjectId} from remote storage", fileObject.Id);
|
||||
}
|
||||
await client.RemoveObjectAsync(
|
||||
new RemoveObjectArgs()
|
||||
.WithBucket(dest.Bucket)
|
||||
.WithObject(replica.StorageId + ".compressed")
|
||||
);
|
||||
}
|
||||
if (fileObject.HasThumbnail)
|
||||
{
|
||||
await client.RemoveObjectAsync(
|
||||
new RemoveObjectArgs()
|
||||
.WithBucket(dest.Bucket)
|
||||
.WithObject(replica.StorageId + ".thumbnail")
|
||||
);
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.LogError(ex, "Failed to delete orphaned file object {ObjectId} from remote storage", fileObject.Id);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -204,7 +204,7 @@ public class FileService(
|
||||
};
|
||||
}
|
||||
|
||||
private async Task<(string processingPath, bool isTempFile)> ProcessEncryptionAsync(
|
||||
private Task<(string processingPath, bool isTempFile)> ProcessEncryptionAsync(
|
||||
string fileId,
|
||||
string managedTempPath,
|
||||
string? encryptPassword,
|
||||
@@ -213,7 +213,7 @@ public class FileService(
|
||||
)
|
||||
{
|
||||
if (string.IsNullOrWhiteSpace(encryptPassword))
|
||||
return (managedTempPath, true);
|
||||
return Task.FromResult((managedTempPath, true));
|
||||
|
||||
if (!pool.PolicyConfig.AllowEncryption)
|
||||
throw new InvalidOperationException("Encryption is not allowed in this pool");
|
||||
@@ -227,7 +227,7 @@ public class FileService(
|
||||
file.MimeType = "application/octet-stream";
|
||||
file.Size = new FileInfo(encryptedPath).Length;
|
||||
|
||||
return (encryptedPath, true);
|
||||
return Task.FromResult((encryptedPath, true));
|
||||
}
|
||||
|
||||
private async Task SaveFileToDatabaseAsync(SnCloudFile file)
|
||||
@@ -248,7 +248,7 @@ public class FileService(
|
||||
{
|
||||
Id = Guid.NewGuid(),
|
||||
ObjectId = file.Id,
|
||||
PoolId = file.PoolId!.Value,
|
||||
PoolId = file.PoolId,
|
||||
StorageId = file.StorageId ?? file.Id,
|
||||
Status = SnFileReplicaStatus.Available,
|
||||
IsPrimary = true
|
||||
@@ -616,7 +616,7 @@ public class FileService(
|
||||
.Where(r => objectIds.Contains(r.ObjectId))
|
||||
.ToListAsync();
|
||||
|
||||
foreach (var poolGroup in replicas.GroupBy(r => r.PoolId))
|
||||
foreach (var poolGroup in replicas.Where(r => r.PoolId.HasValue).GroupBy(r => r.PoolId!.Value))
|
||||
{
|
||||
var dest = await GetRemoteStorageConfig(poolGroup.Key);
|
||||
if (dest is null)
|
||||
@@ -860,4 +860,4 @@ file class UpdatableCloudFile(SnCloudFile file)
|
||||
.SetProperty(f => f.UserMeta, userMeta)
|
||||
.SetProperty(f => f.IsMarkedRecycle, IsMarkedRecycle);
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user