Skip to content

Kavita is a fast, feature rich, cross platform reading server. Built with the goal of being a full solution for all your reading needs. Setup your own server and share your reading collection with your friends and family.

Fix Backups (#750)

Joseph Milazzoae5c6594e409
diff --git a/API/Services/DirectoryService.cs b/API/Services/DirectoryService.cs
index 12011123d..b9560084f 100644
--- a/API/Services/DirectoryService.cs
+++ b/API/Services/DirectoryService.cs
@@ -22,6 +22,7 @@ namespace API.Services
public static readonly string CoverImageDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "covers");
public static readonly string BackupDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "backups");
public static readonly string StatsDirectory = Path.Join(Directory.GetCurrentDirectory(), "config", "stats");
+ public static readonly string ConfigDirectory = Path.Join(Directory.GetCurrentDirectory(), "config");
public DirectoryService(ILogger<DirectoryService> logger)
{
diff --git a/API/Services/Tasks/BackupService.cs b/API/Services/Tasks/BackupService.cs
index e71f35e9f..bf1f26711 100644
--- a/API/Services/Tasks/BackupService.cs
+++ b/API/Services/Tasks/BackupService.cs
@@ -89,7 +89,7 @@ namespace API.Services.Tasks
_logger.LogDebug("Backing up to {BackupDirectory}", backupDirectory);
if (!DirectoryService.ExistOrCreate(backupDirectory))
{
- _logger.LogError("Could not write to {BackupDirectory}; aborting backup", backupDirectory);
+ _logger.LogCritical("Could not write to {BackupDirectory}; aborting backup", backupDirectory);
return;
}
@@ -107,7 +107,7 @@ namespace API.Services.Tasks
DirectoryService.ClearDirectory(tempDirectory);
_directoryService.CopyFilesToDirectory(
- _backupFiles.Select(file => Path.Join(Directory.GetCurrentDirectory(), file)).ToList(), tempDirectory);
+ _backupFiles.Select(file => Path.Join(DirectoryService.ConfigDirectory, file)).ToList(), tempDirectory);
await CopyCoverImagesToBackupDirectory(tempDirectory);
diff --git a/API/Services/Tasks/ScannerService.cs b/API/Services/Tasks/ScannerService.cs
index 38497aac2..c2abe341f 100644
--- a/API/Services/Tasks/ScannerService.cs
+++ b/API/Services/Tasks/ScannerService.cs
@@ -359,9 +359,9 @@ namespace API.Services.Tasks
// Key is normalized already
Series existingSeries;
try
- {// NOTE: Maybe use .Equals() here
+ {
existingSeries = allSeries.SingleOrDefault(s =>
- (s.NormalizedName == key.NormalizedName || Parser.Parser.Normalize(s.OriginalName) == key.NormalizedName)
+ (s.NormalizedName.Equals(key.NormalizedName) || Parser.Parser.Normalize(s.OriginalName).Equals(key.NormalizedName))
&& (s.Format == key.Format || s.Format == MangaFormat.Unknown));
}
catch (Exception e)
@@ -393,31 +393,24 @@ namespace API.Services.Tasks
series.Pages = series.Volumes.Sum(v => v.Pages);
series.LibraryId = library.Id; // We have to manually set this since we aren't adding the series to the Library's series.
_unitOfWork.SeriesRepository.Attach(series);
- if (await _unitOfWork.CommitAsync())
- {
- _logger.LogInformation(
- "[ScannerService] Added {NewSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",
- newSeries.Count, stopwatch.ElapsedMilliseconds, library.Name);
-
- // Inform UI of new series added
- await _messageHub.Clients.All.SendAsync(SignalREvents.SeriesAdded, MessageFactory.SeriesAddedEvent(series.Id, series.Name, library.Id));
- var progress = Math.Max(0F, Math.Min(100F, i * 1F / newSeries.Count));
- await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,
- MessageFactory.ScanLibraryProgressEvent(library.Id, progress));
- }
- else
- {
- // This is probably not needed. Better to catch the exception.
- _logger.LogCritical(
- "[ScannerService] There was a critical error that resulted in a failed scan. Please check logs and rescan");
- }
+ await _unitOfWork.CommitAsync();
+ _logger.LogInformation(
+ "[ScannerService] Added {NewSeries} series in {ElapsedScanTime} milliseconds for {LibraryName}",
+ newSeries.Count, stopwatch.ElapsedMilliseconds, library.Name);
- i++;
+ // Inform UI of new series added
+ await _messageHub.Clients.All.SendAsync(SignalREvents.SeriesAdded, MessageFactory.SeriesAddedEvent(series.Id, series.Name, library.Id));
}
catch (Exception ex)
{
- _logger.LogError(ex, "[ScannerService] There was an exception updating volumes for {SeriesName}", series.Name);
+ _logger.LogCritical(ex, "[ScannerService] There was a critical exception adding new series entry for {SeriesName} with a duplicate index key: {IndexKey}",
+ series.Name, $"{series.Name}_{series.NormalizedName}_{series.LocalizedName}_{series.LibraryId}_{series.Format}");
}
+
+ var progress = Math.Max(0F, Math.Min(100F, i * 1F / newSeries.Count));
+ await _messageHub.Clients.All.SendAsync(SignalREvents.ScanLibraryProgress,
+ MessageFactory.ScanLibraryProgressEvent(library.Id, progress));
+ i++;
}
_logger.LogInformation(