Fixed amended temp file clean-up routine to restore behaviour of continuing on single file error.
This commit is contained in:
@@ -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<Error> 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<Error> 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; }
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -224,6 +224,7 @@ namespace Umbraco.Core.IO
|
||||
}
|
||||
|
||||
var files = folder.GetFiles("*.*", SearchOption.AllDirectories);
|
||||
var errors = new List<CleanFolderResult.Error>();
|
||||
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();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user