From 8ec4bccc06c1d963566bd79ad7b6887998bd3dec Mon Sep 17 00:00:00 2001 From: Mikal Stordal Date: Wed, 9 Oct 2024 03:27:47 +0200 Subject: [PATCH] fix: remove VFS library roots with the same id but wrong parent folder - Remove any and all VFS library roots from the library with the correct library ID but the wrong parent folder(s). --- Shokofin/Configuration/MediaFolderConfigurationService.cs | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/Shokofin/Configuration/MediaFolderConfigurationService.cs b/Shokofin/Configuration/MediaFolderConfigurationService.cs index 7ee20a1f..1f8a41d6 100644 --- a/Shokofin/Configuration/MediaFolderConfigurationService.cs +++ b/Shokofin/Configuration/MediaFolderConfigurationService.cs @@ -330,6 +330,7 @@ private async Task GenerateAllConfigurations(List allVirtualF continue; var vfsPath = libraryFolder.GetVirtualRoot(); + var vfsFolderName = Path.GetFileName(vfsPath); var shouldAttach = config.VFS_AttachRoot && mediaFolderConfig.IsVirtualFileSystemEnabled; if (shouldAttach && !virtualFolder.Locations.Contains(vfsPath, Path.DirectorySeparatorChar is '\\' ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal)) { if (!LibraryEdits.TryGetValue(libraryId, out var edits)) @@ -339,7 +340,11 @@ private async Task GenerateAllConfigurations(List allVirtualF var toRemove = virtualFolder.Locations .Except(shouldAttach ? [vfsPath] : []) - .Where(location => Plugin.Instance.AllVirtualRoots.Any(virtualRoot => location.StartsWith(virtualRoot, Path.DirectorySeparatorChar is '\\' ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))) + .Where(location => + // In case the VFS root changes. + (string.Equals(Path.GetFileName(location), vfsFolderName) && !string.Equals(location, vfsPath)) || + // In case the libraryId changes but the root remains the same. + Plugin.Instance.AllVirtualRoots.Any(virtualRoot => location.StartsWith(virtualRoot, Path.DirectorySeparatorChar is '\\' ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))) .ToList(); if (toRemove.Count > 0) { if (!LibraryEdits.TryGetValue(libraryId, out var edits))