From 7a5ba39603c2a0c970c619016686431b7ff14df1 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Fri, 24 May 2013 13:48:48 -0400 Subject: [PATCH] fixes #305 - Multiple collections --- MediaBrowser.Api/Library/LibraryHelpers.cs | 7 ------- MediaBrowser.Controller/Entities/BaseItem.cs | 12 ++++++++++++ .../Entities/CollectionFolder.cs | 13 +++++++------ .../Library/LibraryManager.cs | 12 ++++++++++++ 4 files changed, 31 insertions(+), 13 deletions(-) diff --git a/MediaBrowser.Api/Library/LibraryHelpers.cs b/MediaBrowser.Api/Library/LibraryHelpers.cs index ff0915d78..d3b7861a6 100644 --- a/MediaBrowser.Api/Library/LibraryHelpers.cs +++ b/MediaBrowser.Api/Library/LibraryHelpers.cs @@ -203,7 +203,6 @@ namespace MediaBrowser.Api.Library { // Example: D:\Movies is the existing path // D:\ cannot be added - // Neither can D:\Movies\Kids // A D:\Movies duplicate is ok here since that will be caught later if (newPath.Equals(existingPath, StringComparison.OrdinalIgnoreCase)) @@ -211,12 +210,6 @@ namespace MediaBrowser.Api.Library return true; } - // Validate the D:\Movies\Kids scenario - if (newPath.StartsWith(existingPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) - { - return false; - } - // Validate the D:\ scenario if (existingPath.StartsWith(newPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)) { diff --git a/MediaBrowser.Controller/Entities/BaseItem.cs b/MediaBrowser.Controller/Entities/BaseItem.cs index ac8688f77..898280110 100644 --- a/MediaBrowser.Controller/Entities/BaseItem.cs +++ b/MediaBrowser.Controller/Entities/BaseItem.cs @@ -384,6 +384,18 @@ namespace MediaBrowser.Controller.Entities var flattenFolderDepth = isPhysicalRoot ? 2 : 0; args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, Logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf); + + // Need to remove subpaths that may have been resolved from shortcuts + // Example: if \\server\movies exists, then strip out \\server\movies\action + if (isPhysicalRoot) + { + var paths = args.FileSystemDictionary.Keys.ToList(); + + foreach (var subPath in paths.Where(subPath => paths.Any(i => subPath.StartsWith(i.TrimEnd(System.IO.Path.DirectorySeparatorChar) + System.IO.Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)))) + { + args.FileSystemDictionary.Remove(subPath); + } + } } //update our dates diff --git a/MediaBrowser.Controller/Entities/CollectionFolder.cs b/MediaBrowser.Controller/Entities/CollectionFolder.cs index 64e5da92e..723ab4756 100644 --- a/MediaBrowser.Controller/Entities/CollectionFolder.cs +++ b/MediaBrowser.Controller/Entities/CollectionFolder.cs @@ -1,5 +1,4 @@ using MediaBrowser.Common.Extensions; -using MediaBrowser.Model.Entities; using System; using System.Collections.Concurrent; using System.Collections.Generic; @@ -74,23 +73,25 @@ namespace MediaBrowser.Controller.Entities { get { - IEnumerable folderIds; + Dictionary folderIds; try { // Accessing ResolveArgs could involve file system access - folderIds = ResolveArgs.PhysicalLocations.Select(f => (f.GetMBId(typeof(Folder)))); + folderIds = ResolveArgs.PhysicalLocations + .Select(f => (f.GetMBId(typeof(Folder)))) + .ToDictionary(i => i); } catch (IOException ex) { Logger.ErrorException("Error creating FolderIds for {0}", ex, Path); - folderIds = new Guid[] {}; + folderIds = new Dictionary(); } var ourChildren = - LibraryManager.RootFolder.Children.OfType() - .Where(i => folderIds.Contains(i.Id)) + LibraryManager.RootFolder.RecursiveChildren.OfType() + .Where(i => folderIds.ContainsKey(i.Id)) .SelectMany(c => c.Children); return new ConcurrentDictionary(ourChildren.ToDictionary(i => i.Id)); diff --git a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs index 13857a656..af0212738 100644 --- a/MediaBrowser.Server.Implementations/Library/LibraryManager.cs +++ b/MediaBrowser.Server.Implementations/Library/LibraryManager.cs @@ -430,6 +430,18 @@ namespace MediaBrowser.Server.Implementations.Library var flattenFolderDepth = isPhysicalRoot ? 2 : 0; args.FileSystemDictionary = FileData.GetFilteredFileSystemEntries(args.Path, _logger, flattenFolderDepth: flattenFolderDepth, args: args, resolveShortcuts: isPhysicalRoot || args.IsVf); + + // Need to remove subpaths that may have been resolved from shortcuts + // Example: if \\server\movies exists, then strip out \\server\movies\action + if (isPhysicalRoot) + { + var paths = args.FileSystemDictionary.Keys.ToList(); + + foreach (var subPath in paths.Where(subPath => paths.Any(i => subPath.StartsWith(i.TrimEnd(System.IO.Path.DirectorySeparatorChar) + System.IO.Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase)))) + { + args.FileSystemDictionary.Remove(subPath); + } + } } // Check to see if we should resolve based on our contents