From dadf3c67bfa055fd7def8fb16881d5cfc4c034cb Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Tue, 13 Jan 2026 00:39:52 +0800 Subject: [PATCH] :bug: Trying to fix the file migration service --- DysonNetwork.Drive/Storage/FileMigrationService.cs | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/DysonNetwork.Drive/Storage/FileMigrationService.cs b/DysonNetwork.Drive/Storage/FileMigrationService.cs index 29055f6c..b4943c3b 100644 --- a/DysonNetwork.Drive/Storage/FileMigrationService.cs +++ b/DysonNetwork.Drive/Storage/FileMigrationService.cs @@ -1,6 +1,5 @@ using DysonNetwork.Shared.Models; using Microsoft.EntityFrameworkCore; -using System.IO; namespace DysonNetwork.Drive.Storage; @@ -13,8 +12,7 @@ public class FileMigrationService(AppDatabase db, ILogger var cloudFiles = await db.Files .Where(f => f.ObjectId == null && - f.PoolId != null && - !db.FileObjects.Any(fo => fo.Id == f.Id) + f.PoolId != null ) .ToListAsync(); @@ -22,6 +20,12 @@ public class FileMigrationService(AppDatabase db, ILogger foreach (var cf in cloudFiles) { + if (await db.FileObjects.AnyAsync(fo => fo.Id == cf.Id)) + { + logger.LogWarning("FileObject for {Id} already exists, skipping.", cf.Id); + continue; + } + var ext = Path.GetExtension(cf.Name); var mimeType = ext != "" && MimeTypes.TryGetMimeType(ext, out var mime) ? mime : "application/octet-stream";