From a60fe36c33a346fe575213851bf233da9f794dd8 Mon Sep 17 00:00:00 2001 From: Andy Butland Date: Sat, 31 Oct 2020 14:46:56 +0100 Subject: [PATCH] Fixed amended temp file clean-up routine to restore behaviour of continuing on single file error. --- src/Umbraco.Core/IO/CleanFolderResult.cs | 25 +++++++++++++------ src/Umbraco.Core/IO/IOHelper.cs | 8 +++--- .../HostedServices/TempFileCleanup.cs | 6 ++++- 3 files changed, 28 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Core/IO/CleanFolderResult.cs b/src/Umbraco.Core/IO/CleanFolderResult.cs index b85705ea83..eb783f230d 100644 --- a/src/Umbraco.Core/IO/CleanFolderResult.cs +++ b/src/Umbraco.Core/IO/CleanFolderResult.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; namespace Umbraco.Core.IO @@ -16,11 +17,9 @@ namespace Umbraco.Core.IO { } - public CleanFolderResultStatus Status { get; set; } + public CleanFolderResultStatus Status { get; private set; } - public Exception Exception { get; set; } - - public FileInfo ErroringFile { get; set; } + public IReadOnlyCollection Errors { get; private set; } public static CleanFolderResult Success() { @@ -32,14 +31,26 @@ namespace Umbraco.Core.IO return new CleanFolderResult { Status = CleanFolderResultStatus.FailedAsDoesNotExist }; } - public static CleanFolderResult FailedWithException(Exception exception, FileInfo erroringFile) + public static CleanFolderResult FailedWithErrors(List errors) { return new CleanFolderResult { Status = CleanFolderResultStatus.FailedWithException, - Exception = exception, - ErroringFile = erroringFile, + Errors = errors.AsReadOnly(), }; } + + public class Error + { + public Error(Exception exception, FileInfo erroringFile) + { + Exception = exception; + ErroringFile = erroringFile; + } + + public Exception Exception { get; set; } + + public FileInfo ErroringFile { get; set; } + } } } diff --git a/src/Umbraco.Core/IO/IOHelper.cs b/src/Umbraco.Core/IO/IOHelper.cs index 260c6923ed..f14dabd7ee 100644 --- a/src/Umbraco.Core/IO/IOHelper.cs +++ b/src/Umbraco.Core/IO/IOHelper.cs @@ -224,6 +224,7 @@ namespace Umbraco.Core.IO } var files = folder.GetFiles("*.*", SearchOption.AllDirectories); + var errors = new List(); foreach (var file in files) { if (DateTime.UtcNow - file.LastWriteTimeUtc > age) @@ -235,13 +236,14 @@ namespace Umbraco.Core.IO } catch (Exception ex) { - return CleanFolderResult.FailedWithException(ex, file); + errors.Add(new CleanFolderResult.Error(ex, file)); } } } - return CleanFolderResult.Success(); + return errors.Any() + ? CleanFolderResult.FailedWithErrors(errors) + : CleanFolderResult.Success(); } - } } diff --git a/src/Umbraco.Infrastructure/HostedServices/TempFileCleanup.cs b/src/Umbraco.Infrastructure/HostedServices/TempFileCleanup.cs index 5b5feca029..3e565b0112 100644 --- a/src/Umbraco.Infrastructure/HostedServices/TempFileCleanup.cs +++ b/src/Umbraco.Infrastructure/HostedServices/TempFileCleanup.cs @@ -56,7 +56,11 @@ namespace Umbraco.Infrastructure.HostedServices _logger.LogDebug("The cleanup folder doesn't exist {Folder}", folder.FullName); break; case CleanFolderResultStatus.FailedWithException: - _logger.LogError(result.Exception, "Could not delete temp file {FileName}", result.ErroringFile.FullName); + foreach (var error in result.Errors) + { + _logger.LogError(error.Exception, "Could not delete temp file {FileName}", error.ErroringFile.FullName); + } + break; }