Skip to content

Commit

Permalink
fix: auto remove old media folder mappings
Browse files Browse the repository at this point in the history
- Automagically remove old media folder mappings.
  • Loading branch information
revam committed Oct 14, 2024
1 parent 74418da commit c940504
Showing 1 changed file with 10 additions and 1 deletion.
11 changes: 10 additions & 1 deletion Shokofin/Configuration/MediaFolderConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ private async Task GenerateAllConfigurations(List<VirtualFolderInfo> allVirtualF
foreach (var mediaFolderPath in virtualFolder.Locations) {
if (LibraryManager.FindByPath(mediaFolderPath, true) is not Folder secondFolder)
{
Logger.LogTrace("Unable to find database entry for {Path}", mediaFolderPath);
Logger.LogTrace("Unable to find database entry for {Path} (Library={LibraryId})", mediaFolderPath, libraryId);
continue;
}

Expand Down Expand Up @@ -353,6 +353,15 @@ private async Task GenerateAllConfigurations(List<VirtualFolderInfo> allVirtualF
edits.remove.Add(location);
}
}

var mediaFoldersToRemove = config.MediaFolders
.Where(c => !filteredVirtualFolders.Any(v => Guid.Parse(v.ItemId) == c.LibraryId))
.ToList();
Logger.LogDebug("Found {Count} out of {TotalCount} media folders to remove.", mediaFoldersToRemove.Count, config.MediaFolders.Count);
foreach (var mediaFolder in mediaFoldersToRemove) {
Logger.LogTrace("Removing config for media folder at path {Path} (Library={LibraryId})", mediaFolder.MediaFolderPath, mediaFolder.LibraryId);
config.MediaFolders.Remove(mediaFolder);
}
}

private async Task<MediaFolderConfiguration> CreateConfigurationForPath(Guid libraryId, Folder mediaFolder, MediaFolderConfiguration? libraryConfig)
Expand Down

0 comments on commit c940504

Please sign in to comment.