From 39e84115947e6b0ba2836be17fc4c2b562ee6960 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Thu, 26 Dec 2013 19:52:36 -0500 Subject: [PATCH] fixed validation not refreshing virtual items --- MediaBrowser.Controller/Entities/Folder.cs | 195 +++++++++++---------- 1 file changed, 98 insertions(+), 97 deletions(-) diff --git a/MediaBrowser.Controller/Entities/Folder.cs b/MediaBrowser.Controller/Entities/Folder.cs index 8ef86e54e..fed206a30 100644 --- a/MediaBrowser.Controller/Entities/Folder.cs +++ b/MediaBrowser.Controller/Entities/Folder.cs @@ -8,7 +8,6 @@ using MediaBrowser.Model.Entities; using MoreLinq; using System; using System.Collections; -using System.Collections.Concurrent; using System.Collections.Generic; using System.IO; using System.Linq; @@ -365,123 +364,125 @@ namespace MediaBrowser.Controller.Entities { var locationType = LocationType; - // Nothing to do here - if (locationType == LocationType.Remote || locationType == LocationType.Virtual) - { - return; - } - cancellationToken.ThrowIfCancellationRequested(); - IEnumerable nonCachedChildren; - - try - { - nonCachedChildren = GetNonCachedChildren(); - } - catch (IOException ex) - { - nonCachedChildren = new BaseItem[] { }; - - Logger.ErrorException("Error getting file system entries for {0}", ex, Path); - } - - if (nonCachedChildren == null) return; //nothing to validate - - progress.Report(5); - - //build a dictionary of the current children we have now by Id so we can compare quickly and easily - var currentChildren = ActualChildren.ToDictionary(i => i.Id); - - //create a list for our validated children var validChildren = new List>(); - var newItems = new List(); - cancellationToken.ThrowIfCancellationRequested(); - - foreach (var child in nonCachedChildren) + if (locationType != LocationType.Remote && locationType != LocationType.Virtual) { - BaseItem currentChild; + IEnumerable nonCachedChildren; - if (currentChildren.TryGetValue(child.Id, out currentChild)) + try { - currentChild.ResetResolveArgs(child.ResolveArgs); + nonCachedChildren = GetNonCachedChildren(); + } + catch (IOException ex) + { + nonCachedChildren = new BaseItem[] {}; - //existing item - check if it has changed - if (currentChild.HasChanged(child)) + Logger.ErrorException("Error getting file system entries for {0}", ex, Path); + } + + if (nonCachedChildren == null) return; //nothing to validate + + progress.Report(5); + + //build a dictionary of the current children we have now by Id so we can compare quickly and easily + var currentChildren = ActualChildren.ToDictionary(i => i.Id); + + //create a list for our validated children + var newItems = new List(); + + cancellationToken.ThrowIfCancellationRequested(); + + foreach (var child in nonCachedChildren) + { + BaseItem currentChild; + + if (currentChildren.TryGetValue(child.Id, out currentChild)) { - var currentChildLocationType = currentChild.LocationType; - if (currentChildLocationType != LocationType.Remote && - currentChildLocationType != LocationType.Virtual) + currentChild.ResetResolveArgs(child.ResolveArgs); + + //existing item - check if it has changed + if (currentChild.HasChanged(child)) { - EntityResolutionHelper.EnsureDates(FileSystem, currentChild, child.ResolveArgs, false); + var currentChildLocationType = currentChild.LocationType; + if (currentChildLocationType != LocationType.Remote && + currentChildLocationType != LocationType.Virtual) + { + EntityResolutionHelper.EnsureDates(FileSystem, currentChild, child.ResolveArgs, false); + } + + validChildren.Add(new Tuple(currentChild, true)); + } + else + { + validChildren.Add(new Tuple(currentChild, false)); } - validChildren.Add(new Tuple(currentChild, true)); + currentChild.IsOffline = false; } else { - validChildren.Add(new Tuple(currentChild, false)); + //brand new item - needs to be added + newItems.Add(child); + + validChildren.Add(new Tuple(child, true)); + } + } + + // If any items were added or removed.... + if (newItems.Count > 0 || currentChildren.Count != validChildren.Count) + { + var newChildren = validChildren.Select(c => c.Item1).ToList(); + + // That's all the new and changed ones - now see if there are any that are missing + var itemsRemoved = currentChildren.Values.Except(newChildren).ToList(); + + var actualRemovals = new List(); + + foreach (var item in itemsRemoved) + { + if (item.LocationType == LocationType.Virtual || + item.LocationType == LocationType.Remote) + { + // Don't remove these because there's no way to accurately validate them. + validChildren.Add(new Tuple(item, false)); + } + + else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path)) + { + item.IsOffline = true; + + validChildren.Add(new Tuple(item, false)); + } + else + { + item.IsOffline = false; + actualRemovals.Add(item); + } } - currentChild.IsOffline = false; - } - else - { - //brand new item - needs to be added - newItems.Add(child); + if (actualRemovals.Count > 0) + { + RemoveChildrenInternal(actualRemovals); - validChildren.Add(new Tuple(child, true)); + foreach (var item in actualRemovals) + { + LibraryManager.ReportItemRemoved(item); + } + } + + await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false); + + AddChildrenInternal(newItems); + + await ItemRepository.SaveChildren(Id, ActualChildren.Select(i => i.Id).ToList(), cancellationToken).ConfigureAwait(false); } } - - // If any items were added or removed.... - if (newItems.Count > 0 || currentChildren.Count != validChildren.Count) + else { - var newChildren = validChildren.Select(c => c.Item1).ToList(); - - // That's all the new and changed ones - now see if there are any that are missing - var itemsRemoved = currentChildren.Values.Except(newChildren).ToList(); - - var actualRemovals = new List(); - - foreach (var item in itemsRemoved) - { - if (item.LocationType == LocationType.Virtual || - item.LocationType == LocationType.Remote) - { - // Don't remove these because there's no way to accurately validate them. - continue; - } - - if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path)) - { - item.IsOffline = true; - - validChildren.Add(new Tuple(item, false)); - } - else - { - item.IsOffline = false; - actualRemovals.Add(item); - } - } - - if (actualRemovals.Count > 0) - { - RemoveChildrenInternal(actualRemovals); - - foreach (var item in actualRemovals) - { - LibraryManager.ReportItemRemoved(item); - } - } - - await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false); - - AddChildrenInternal(newItems); - - await ItemRepository.SaveChildren(Id, ActualChildren.Select(i => i.Id).ToList(), cancellationToken).ConfigureAwait(false); + validChildren.AddRange(ActualChildren.Select(i => new Tuple(i, false))); } progress.Report(10);