From 4fd1ce3d6e8c6c8499e2dc18815d72a7134eb043 Mon Sep 17 00:00:00 2001 From: Stanley Dimant Date: Fri, 6 Sep 2024 10:51:52 +0200 Subject: [PATCH] add try catch to the initial file rawsize calc --- .../Services/MainFileCleanupService.cs | 27 ++++++++++++------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/MainFileCleanupService.cs b/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/MainFileCleanupService.cs index 1144363..de889e8 100644 --- a/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/MainFileCleanupService.cs +++ b/MareSynchronosServer/MareSynchronosStaticFilesServer/Services/MainFileCleanupService.cs @@ -243,6 +243,23 @@ public class MainFileCleanupService : IHostedService deleteCurrentFile = true; } + // only used if file in db has no raw size for whatever reason + if (!deleteCurrentFile && file != null && fileCache.RawSize == 0) + { + try + { + var length = LZ4Codec.Unwrap(File.ReadAllBytes(file.FullName)).LongLength; + _logger.LogInformation("Setting Raw File Size of " + fileCache.Hash + " to " + length); + fileCache.RawSize = length; + if (fileCounter % 1000 == 0) + await dbContext.SaveChangesAsync().ConfigureAwait(false); + } + catch (Exception ex) + { + _logger.LogError(ex, "Could not unpack {fileName}", file.FullName); + } + } + // do actual deletion of file and remove also from db if needed if (deleteCurrentFile) { @@ -263,16 +280,6 @@ public class MainFileCleanupService : IHostedService await dbContext.SaveChangesAsync().ConfigureAwait(false); } - // only used if file in db has no raw size for whatever reason - if (!deleteCurrentFile && file != null && fileCache.RawSize == 0) - { - var length = LZ4Codec.Unwrap(File.ReadAllBytes(file.FullName)).LongLength; - _logger.LogInformation("Setting Raw File Size of " + fileCache.Hash + " to " + length); - fileCache.RawSize = length; - if (fileCounter % 1000 == 0) - await dbContext.SaveChangesAsync().ConfigureAwait(false); - } - fileCounter++; ct.ThrowIfCancellationRequested();