fixed validation not refreshing virtual items

pull/702/head
Luke Pulverenti 11 years ago
parent 809ed093e8
commit 39e8411594

@ -8,7 +8,6 @@ using MediaBrowser.Model.Entities;
using MoreLinq; using MoreLinq;
using System; using System;
using System.Collections; using System.Collections;
using System.Collections.Concurrent;
using System.Collections.Generic; using System.Collections.Generic;
using System.IO; using System.IO;
using System.Linq; using System.Linq;
@ -365,123 +364,125 @@ namespace MediaBrowser.Controller.Entities
{ {
var locationType = LocationType; var locationType = LocationType;
// Nothing to do here
if (locationType == LocationType.Remote || locationType == LocationType.Virtual)
{
return;
}
cancellationToken.ThrowIfCancellationRequested(); cancellationToken.ThrowIfCancellationRequested();
IEnumerable<BaseItem> nonCachedChildren; var validChildren = new List<Tuple<BaseItem, bool>>();
try if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
{
nonCachedChildren = GetNonCachedChildren();
}
catch (IOException ex)
{ {
nonCachedChildren = new BaseItem[] { }; IEnumerable<BaseItem> nonCachedChildren;
Logger.ErrorException("Error getting file system entries for {0}", ex, Path); try
} {
nonCachedChildren = GetNonCachedChildren();
}
catch (IOException ex)
{
nonCachedChildren = new BaseItem[] {};
if (nonCachedChildren == null) return; //nothing to validate Logger.ErrorException("Error getting file system entries for {0}", ex, Path);
}
progress.Report(5); if (nonCachedChildren == null) return; //nothing to validate
//build a dictionary of the current children we have now by Id so we can compare quickly and easily progress.Report(5);
var currentChildren = ActualChildren.ToDictionary(i => i.Id);
//create a list for our validated children //build a dictionary of the current children we have now by Id so we can compare quickly and easily
var validChildren = new List<Tuple<BaseItem, bool>>(); var currentChildren = ActualChildren.ToDictionary(i => i.Id);
var newItems = new List<BaseItem>();
cancellationToken.ThrowIfCancellationRequested(); //create a list for our validated children
var newItems = new List<BaseItem>();
foreach (var child in nonCachedChildren) cancellationToken.ThrowIfCancellationRequested();
{
BaseItem currentChild;
if (currentChildren.TryGetValue(child.Id, out currentChild)) foreach (var child in nonCachedChildren)
{ {
currentChild.ResetResolveArgs(child.ResolveArgs); BaseItem currentChild;
//existing item - check if it has changed if (currentChildren.TryGetValue(child.Id, out currentChild))
if (currentChild.HasChanged(child))
{ {
var currentChildLocationType = currentChild.LocationType; currentChild.ResetResolveArgs(child.ResolveArgs);
if (currentChildLocationType != LocationType.Remote &&
currentChildLocationType != LocationType.Virtual) //existing item - check if it has changed
if (currentChild.HasChanged(child))
{
var currentChildLocationType = currentChild.LocationType;
if (currentChildLocationType != LocationType.Remote &&
currentChildLocationType != LocationType.Virtual)
{
EntityResolutionHelper.EnsureDates(FileSystem, currentChild, child.ResolveArgs, false);
}
validChildren.Add(new Tuple<BaseItem, bool>(currentChild, true));
}
else
{ {
EntityResolutionHelper.EnsureDates(FileSystem, currentChild, child.ResolveArgs, false); validChildren.Add(new Tuple<BaseItem, bool>(currentChild, false));
} }
validChildren.Add(new Tuple<BaseItem, bool>(currentChild, true)); currentChild.IsOffline = false;
} }
else else
{ {
validChildren.Add(new Tuple<BaseItem, bool>(currentChild, false)); //brand new item - needs to be added
} newItems.Add(child);
currentChild.IsOffline = false; validChildren.Add(new Tuple<BaseItem, bool>(child, true));
}
} }
else
// If any items were added or removed....
if (newItems.Count > 0 || currentChildren.Count != validChildren.Count)
{ {
//brand new item - needs to be added var newChildren = validChildren.Select(c => c.Item1).ToList();
newItems.Add(child);
validChildren.Add(new Tuple<BaseItem, bool>(child, true)); // That's all the new and changed ones - now see if there are any that are missing
} var itemsRemoved = currentChildren.Values.Except(newChildren).ToList();
}
// If any items were added or removed.... var actualRemovals = new List<BaseItem>();
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 foreach (var item in itemsRemoved)
var itemsRemoved = currentChildren.Values.Except(newChildren).ToList(); {
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<BaseItem, bool>(item, false));
}
var actualRemovals = new List<BaseItem>(); else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path))
{
item.IsOffline = true;
foreach (var item in itemsRemoved) validChildren.Add(new Tuple<BaseItem, bool>(item, false));
{ }
if (item.LocationType == LocationType.Virtual || else
item.LocationType == LocationType.Remote) {
{ item.IsOffline = false;
// Don't remove these because there's no way to accurately validate them. actualRemovals.Add(item);
continue; }
} }
if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path))
{
item.IsOffline = true;
validChildren.Add(new Tuple<BaseItem, bool>(item, false)); if (actualRemovals.Count > 0)
}
else
{ {
item.IsOffline = false; RemoveChildrenInternal(actualRemovals);
actualRemovals.Add(item);
}
}
if (actualRemovals.Count > 0) foreach (var item in actualRemovals)
{ {
RemoveChildrenInternal(actualRemovals); LibraryManager.ReportItemRemoved(item);
}
foreach (var item in actualRemovals)
{
LibraryManager.ReportItemRemoved(item);
} }
}
await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false); await LibraryManager.CreateItems(newItems, cancellationToken).ConfigureAwait(false);
AddChildrenInternal(newItems); AddChildrenInternal(newItems);
await ItemRepository.SaveChildren(Id, ActualChildren.Select(i => i.Id).ToList(), cancellationToken).ConfigureAwait(false); await ItemRepository.SaveChildren(Id, ActualChildren.Select(i => i.Id).ToList(), cancellationToken).ConfigureAwait(false);
}
}
else
{
validChildren.AddRange(ActualChildren.Select(i => new Tuple<BaseItem, bool>(i, false)));
} }
progress.Report(10); progress.Report(10);

Loading…
Cancel
Save