Skip to content

Commit

Permalink
fix: auto remove 'physical' VFS roots when needed
Browse files Browse the repository at this point in the history
  • Loading branch information
revam committed Sep 25, 2024
1 parent aadf950 commit 00465e5
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Shokofin/Configuration/MediaFolderConfigurationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,6 @@ private void GenerateAllConfigurations(List<VirtualFolderInfo> allVirtualFolders
)
.ToList();
var config = Plugin.Instance.Configuration;
var attachRoot = config.VFS_AttachRoot;
foreach (var virtualFolder in filteredVirtualFolders) {
if (!Guid.TryParse(virtualFolder.ItemId, out var libraryId) || LibraryManager.GetItemById(libraryId) is not Folder libraryFolder)
throw new Exception($"Unable to find virtual folder \"{virtualFolder.Name}\"");
Expand All @@ -306,19 +305,20 @@ private void GenerateAllConfigurations(List<VirtualFolderInfo> allVirtualFolders
mediaFolderConfig = CreateConfigurationForPath(libraryId, secondFolder, libraryConfig).ConfigureAwait(false).GetAwaiter().GetResult();
}

if (!attachRoot || !(mediaFolderConfig?.IsVirtualFileSystemEnabled ?? false))
if (mediaFolderConfig is null)
continue;

var vfsPath = libraryFolder.GetVirtualRoot();
if (!virtualFolder.Locations.Contains(vfsPath, Path.DirectorySeparatorChar is '\\' ? StringComparer.OrdinalIgnoreCase : StringComparer.Ordinal)) {
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))
LibraryEdits[libraryId] = edits = (libraryFolder.Name, [], []);
edits.add.Add(vfsPath);
}

var virtualRoot = Plugin.Instance.VirtualRoot;
var toRemove = virtualFolder.Locations
.Except([vfsPath])
.Except(shouldAttach ? [vfsPath] : [])
.Where(location => location.StartsWith(virtualRoot, Path.DirectorySeparatorChar is '\\' ? StringComparison.OrdinalIgnoreCase : StringComparison.Ordinal))
.ToList();
if (toRemove.Count > 0) {
Expand Down

0 comments on commit 00465e5

Please sign in to comment.