update offline detection
This commit is contained in:
parent
911e5cb490
commit
12f20de68b
|
@ -137,6 +137,11 @@ namespace Emby.Server.Implementations.Data
|
||||||
var numComplete = 0;
|
var numComplete = 0;
|
||||||
var numItems = result.Count;
|
var numItems = result.Count;
|
||||||
|
|
||||||
|
var allLibraryPaths = _libraryManager
|
||||||
|
.GetVirtualFolders()
|
||||||
|
.SelectMany(i => i.Locations)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
foreach (var item in result)
|
foreach (var item in result)
|
||||||
{
|
{
|
||||||
cancellationToken.ThrowIfCancellationRequested();
|
cancellationToken.ThrowIfCancellationRequested();
|
||||||
|
@ -170,9 +175,8 @@ namespace Emby.Server.Implementations.Data
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Folder.IsPathOffline(path))
|
if (Folder.IsPathOffline(path, allLibraryPaths))
|
||||||
{
|
{
|
||||||
await libraryItem.UpdateIsOffline(true).ConfigureAwait(false);
|
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -272,9 +272,6 @@ namespace MediaBrowser.Controller.Entities
|
||||||
[IgnoreDataMember]
|
[IgnoreDataMember]
|
||||||
public virtual string Path { get; set; }
|
public virtual string Path { get; set; }
|
||||||
|
|
||||||
[IgnoreDataMember]
|
|
||||||
public bool IsOffline { get; set; }
|
|
||||||
|
|
||||||
[IgnoreDataMember]
|
[IgnoreDataMember]
|
||||||
public virtual SourceType SourceType { get; set; }
|
public virtual SourceType SourceType { get; set; }
|
||||||
|
|
||||||
|
@ -339,20 +336,6 @@ namespace MediaBrowser.Controller.Entities
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public Task UpdateIsOffline(bool newValue)
|
|
||||||
{
|
|
||||||
var item = this;
|
|
||||||
|
|
||||||
if (item.IsOffline != newValue)
|
|
||||||
{
|
|
||||||
item.IsOffline = newValue;
|
|
||||||
// this is creating too many repeated db updates
|
|
||||||
//return item.UpdateToRepository(ItemUpdateType.None, CancellationToken.None);
|
|
||||||
}
|
|
||||||
|
|
||||||
return Task.FromResult(true);
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Gets or sets the type of the location.
|
/// Gets or sets the type of the location.
|
||||||
/// </summary>
|
/// </summary>
|
||||||
|
|
|
@ -369,6 +369,11 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
var validChildren = new List<BaseItem>();
|
var validChildren = new List<BaseItem>();
|
||||||
|
|
||||||
|
var allLibraryPaths = LibraryManager
|
||||||
|
.GetVirtualFolders()
|
||||||
|
.SelectMany(i => i.Locations)
|
||||||
|
.ToList();
|
||||||
|
|
||||||
if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
|
if (locationType != LocationType.Remote && locationType != LocationType.Virtual)
|
||||||
{
|
{
|
||||||
IEnumerable<BaseItem> nonCachedChildren;
|
IEnumerable<BaseItem> nonCachedChildren;
|
||||||
|
@ -402,7 +407,6 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child))
|
if (currentChildren.TryGetValue(child.Id, out currentChild) && IsValidFromResolver(currentChild, child))
|
||||||
{
|
{
|
||||||
await currentChild.UpdateIsOffline(false).ConfigureAwait(false);
|
|
||||||
validChildren.Add(currentChild);
|
validChildren.Add(currentChild);
|
||||||
|
|
||||||
continue;
|
continue;
|
||||||
|
@ -429,9 +433,8 @@ namespace MediaBrowser.Controller.Entities
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path))
|
else if (!string.IsNullOrEmpty(item.Path) && IsPathOffline(item.Path, allLibraryPaths))
|
||||||
{
|
{
|
||||||
await item.UpdateIsOffline(true).ConfigureAwait(false);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -446,7 +449,6 @@ namespace MediaBrowser.Controller.Entities
|
||||||
Logger.Debug("Removed item: " + item.Path);
|
Logger.Debug("Removed item: " + item.Path);
|
||||||
|
|
||||||
item.SetParent(null);
|
item.SetParent(null);
|
||||||
item.IsOffline = false;
|
|
||||||
await LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false);
|
await LibraryManager.DeleteItem(item, new DeleteOptions { DeleteFileLocation = false }).ConfigureAwait(false);
|
||||||
LibraryManager.ReportItemRemoved(item);
|
LibraryManager.ReportItemRemoved(item);
|
||||||
}
|
}
|
||||||
|
@ -611,6 +613,11 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <param name="path">The path.</param>
|
/// <param name="path">The path.</param>
|
||||||
/// <returns><c>true</c> if the specified path is offline; otherwise, <c>false</c>.</returns>
|
/// <returns><c>true</c> if the specified path is offline; otherwise, <c>false</c>.</returns>
|
||||||
public static bool IsPathOffline(string path)
|
public static bool IsPathOffline(string path)
|
||||||
|
{
|
||||||
|
return IsPathOffline(path, LibraryManager.GetVirtualFolders().SelectMany(i => i.Locations).ToList());
|
||||||
|
}
|
||||||
|
|
||||||
|
public static bool IsPathOffline(string path, List<string> allLibraryPaths)
|
||||||
{
|
{
|
||||||
if (FileSystem.FileExists(path))
|
if (FileSystem.FileExists(path))
|
||||||
{
|
{
|
||||||
|
@ -627,26 +634,15 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (allLibraryPaths.Contains(path, StringComparer.OrdinalIgnoreCase))
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
path = System.IO.Path.GetDirectoryName(path);
|
path = System.IO.Path.GetDirectoryName(path);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (ContainsPath(LibraryManager.GetVirtualFolders(), originalPath))
|
return allLibraryPaths.Any(i => ContainsPath(i, originalPath));
|
||||||
{
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
|
|
||||||
/// <summary>
|
|
||||||
/// Determines whether the specified folders contains path.
|
|
||||||
/// </summary>
|
|
||||||
/// <param name="folders">The folders.</param>
|
|
||||||
/// <param name="path">The path.</param>
|
|
||||||
/// <returns><c>true</c> if the specified folders contains path; otherwise, <c>false</c>.</returns>
|
|
||||||
private static bool ContainsPath(IEnumerable<VirtualFolderInfo> folders, string path)
|
|
||||||
{
|
|
||||||
return folders.SelectMany(i => i.Locations).Any(i => ContainsPath(i, path));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private static bool ContainsPath(string parent, string path)
|
private static bool ContainsPath(string parent, string path)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user