Handle corrupted LibraryScans.zip file (#1185)
This commit is contained in:
parent
65e12d9a8f
commit
ee05ca4eb2
@ -233,13 +233,42 @@ namespace ApplicationServices
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static LogArchiver? openLogArchive(string? archivePath)
|
||||||
|
{
|
||||||
|
if (string.IsNullOrWhiteSpace(archivePath))
|
||||||
|
return null;
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
return new LogArchiver(archivePath);
|
||||||
|
}
|
||||||
|
catch (System.IO.InvalidDataException)
|
||||||
|
{
|
||||||
|
try
|
||||||
|
{
|
||||||
|
Log.Logger.Warning($"Deleting corrupted {nameof(LogArchiver)} at {archivePath}");
|
||||||
|
FileUtility.SaferDelete(archivePath);
|
||||||
|
return new LogArchiver(archivePath);
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Logger.Error(ex, $"Failed to open {nameof(LogArchiver)} at {archivePath}");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (Exception ex)
|
||||||
|
{
|
||||||
|
Log.Logger.Error(ex, $"Failed to open {nameof(LogArchiver)} at {archivePath}");
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
private static async Task<List<ImportItem>> scanAccountsAsync(Func<Account, Task<ApiExtended>> apiExtendedfunc, Account[] accounts, LibraryOptions libraryOptions)
|
private static async Task<List<ImportItem>> scanAccountsAsync(Func<Account, Task<ApiExtended>> apiExtendedfunc, Account[] accounts, LibraryOptions libraryOptions)
|
||||||
{
|
{
|
||||||
var tasks = new List<Task<List<ImportItem>>>();
|
var tasks = new List<Task<List<ImportItem>>>();
|
||||||
|
|
||||||
await using LogArchiver? archiver
|
await using LogArchiver? archiver
|
||||||
= Log.Logger.IsDebugEnabled()
|
= Log.Logger.IsDebugEnabled()
|
||||||
? new LogArchiver(System.IO.Path.Combine(Configuration.Instance.LibationFiles, "LibraryScans.zip"))
|
? openLogArchive(System.IO.Path.Combine(Configuration.Instance.LibationFiles, "LibraryScans.zip"))
|
||||||
: default;
|
: default;
|
||||||
|
|
||||||
archiver?.DeleteAllButNewestN(20);
|
archiver?.DeleteAllButNewestN(20);
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user