Browse Source

update CollectionFolder

Luke Pulverenti 9 years ago
parent
commit
6c62c20a9e

+ 1 - 1
MediaBrowser.Controller/Entities/BaseItem.cs

@@ -1542,7 +1542,7 @@ namespace MediaBrowser.Controller.Entities
         {
         {
             if (!string.IsNullOrEmpty(info.Path))
             if (!string.IsNullOrEmpty(info.Path))
             {
             {
-                var itemByPath = LibraryManager.FindByPath(info.Path);
+                var itemByPath = LibraryManager.FindByPath(info.Path, null);
 
 
                 if (itemByPath == null)
                 if (itemByPath == null)
                 {
                 {

+ 24 - 3
MediaBrowser.Controller/Entities/CollectionFolder.cs

@@ -8,6 +8,7 @@ using System.Runtime.Serialization;
 using System.Threading;
 using System.Threading;
 using System.Threading.Tasks;
 using System.Threading.Tasks;
 using CommonIO;
 using CommonIO;
+using MoreLinq;
 
 
 namespace MediaBrowser.Controller.Entities
 namespace MediaBrowser.Controller.Entities
 {
 {
@@ -97,7 +98,6 @@ namespace MediaBrowser.Controller.Entities
                 }
                 }
             }
             }
 
 
-
             return base.IsValidFromResolver(newItem);
             return base.IsValidFromResolver(newItem);
         }
         }
 
 
@@ -200,9 +200,30 @@ namespace MediaBrowser.Controller.Entities
 
 
         public IEnumerable<Folder> GetPhysicalParents()
         public IEnumerable<Folder> GetPhysicalParents()
         {
         {
-            return LibraryManager.RootFolder.Children
+            var rootChildren = LibraryManager.RootFolder.Children
                 .OfType<Folder>()
                 .OfType<Folder>()
-                .Where(i => i.Path != null && PhysicalLocations.Contains(i.Path, StringComparer.OrdinalIgnoreCase));
+                .ToList();
+
+            return PhysicalLocations.Where(i => !string.Equals(i, Path, StringComparison.OrdinalIgnoreCase)).SelectMany(i => GetPhysicalParents(i, rootChildren)).DistinctBy(i => i.Id);
+        }
+
+        private IEnumerable<Folder> GetPhysicalParents(string path, List<Folder> rootChildren)
+        {
+            var result = rootChildren
+                .Where(i => string.Equals(i.Path, path, StringComparison.OrdinalIgnoreCase))
+                .ToList();
+
+            if (result.Count == 0)
+            {
+                var folder = LibraryManager.FindByPath(path, true) as Folder;
+
+                if (folder != null)
+                {
+                    result.Add(folder);
+                }
+            }
+
+            return result;
         }
         }
 
 
         [IgnoreDataMember]
         [IgnoreDataMember]

+ 1 - 1
MediaBrowser.Controller/Library/ILibraryManager.cs

@@ -59,7 +59,7 @@ namespace MediaBrowser.Controller.Library
         /// </summary>
         /// </summary>
         /// <param name="path">The path.</param>
         /// <param name="path">The path.</param>
         /// <returns>BaseItem.</returns>
         /// <returns>BaseItem.</returns>
-        BaseItem FindByPath(string path);
+        BaseItem FindByPath(string path, bool? isFolder);
 
 
         /// <summary>
         /// <summary>
         /// Gets the artist.
         /// Gets the artist.

+ 1 - 1
MediaBrowser.Server.Implementations/IO/LibraryMonitor.cs

@@ -663,7 +663,7 @@ namespace MediaBrowser.Server.Implementations.IO
 
 
             while (item == null && !string.IsNullOrEmpty(path))
             while (item == null && !string.IsNullOrEmpty(path))
             {
             {
-                item = LibraryManager.FindByPath(path);
+                item = LibraryManager.FindByPath(path, null);
 
 
                 path = Path.GetDirectoryName(path);
                 path = Path.GetDirectoryName(path);
             }
             }

+ 3 - 2
MediaBrowser.Server.Implementations/Library/LibraryManager.cs

@@ -801,11 +801,12 @@ namespace MediaBrowser.Server.Implementations.Library
             return _userRootFolder;
             return _userRootFolder;
         }
         }
 
 
-        public BaseItem FindByPath(string path)
+        public BaseItem FindByPath(string path, bool? isFolder)
         {
         {
             var query = new InternalItemsQuery
             var query = new InternalItemsQuery
             {
             {
-                Path = path
+                Path = path,
+                IsFolder = isFolder
             };
             };
 
 
             // Only use the database result if there's exactly one item, otherwise we run the risk of returning old data that hasn't been cleaned yet.
             // Only use the database result if there's exactly one item, otherwise we run the risk of returning old data that hasn't been cleaned yet.