Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/3557 scanner subfolder always scanning #3576

Draft
wants to merge 2 commits into
base: develop
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions API/Services/Tasks/Scanner/ParseScannedFiles.cs
Original file line number Diff line number Diff line change
Expand Up @@ -202,9 +202,14 @@ await _eventHub.SendMessageAsync(MessageFactory.NotificationProgress,
/// <returns></returns>
private bool HasSeriesFolderNotChangedSinceLastScan(IDictionary<string, IList<SeriesModified>> seriesPaths, string directory, bool forceCheck)
{
// With the bottom-up approach, this can report a false positive where a nested folder will get scanned even though a parent is the series
// This can't really be avoided. This is more likely to happen on Image chapter folder library layouts.
if (forceCheck || !seriesPaths.TryGetValue(directory, out var seriesList))
if (forceCheck)
{
return false;
}

// TryGetSeriesList falls back to parent folders to match to seriesList
var seriesList = TryGetSeriesList(seriesPaths, directory);
if (seriesList == null)
{
return false;
}
Expand All @@ -222,6 +227,21 @@ private bool HasSeriesFolderNotChangedSinceLastScan(IDictionary<string, IList<Se
return true;
}

private IList<SeriesModified>? TryGetSeriesList(IDictionary<string, IList<SeriesModified>> seriesPaths, string directory)
{
if (string.IsNullOrEmpty(directory))
{
return null;
}

if (seriesPaths.TryGetValue(directory, out var seriesList))
{
return seriesList;
}

return TryGetSeriesList(seriesPaths, _directoryService.GetParentDirectoryName(directory));
}

/// <summary>
/// Handles directories that haven't changed since the last scan.
/// </summary>
Expand Down Expand Up @@ -721,7 +741,8 @@ private async Task ParseFiles(ScanResult result, IDictionary<string, IList<Serie
// If folder hasn't changed, generate fake ParserInfos
if (!result.HasChanged)
{
result.ParserInfos = seriesPaths[normalizedFolder]
// We are certain TryGetSeriesList will return a valid result here, if the series wasn't present yet. It will have been changed.
result.ParserInfos = TryGetSeriesList(seriesPaths, normalizedFolder)!
.Select(fp => new ParserInfo { Series = fp.SeriesName, Format = fp.Format })
.ToList();

Expand Down