mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-04 06:48:35 +01:00
Some directory-watcher rework - still not working properly
This commit is contained in:
@@ -2,6 +2,7 @@
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using System;
|
||||
using System.Threading.Tasks;
|
||||
using System.Collections.Generic;
|
||||
using System.Linq;
|
||||
|
||||
@@ -179,5 +180,14 @@ namespace MediaBrowser.Controller.Entities
|
||||
data.PlaybackPositionTicks = 0;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Do whatever refreshing is necessary when the filesystem pertaining to this item has changed.
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public virtual Task ChangedExternally()
|
||||
{
|
||||
return Task.Run(() => RefreshMetadata());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -272,7 +272,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Finds child BaseItems for a given Folder
|
||||
/// Finds child BaseItems for us
|
||||
/// </summary>
|
||||
protected Task<BaseItem>[] GetChildren(WIN32_FIND_DATA[] fileSystemChildren)
|
||||
{
|
||||
@@ -328,6 +328,26 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Folders need to validate and refresh
|
||||
/// </summary>
|
||||
/// <returns></returns>
|
||||
public override Task ChangedExternally()
|
||||
{
|
||||
return Task.Run(() =>
|
||||
{
|
||||
if (this.IsRoot)
|
||||
{
|
||||
Kernel.Instance.ReloadRoot().ConfigureAwait(false);
|
||||
}
|
||||
else
|
||||
{
|
||||
RefreshMetadata();
|
||||
ValidateChildren();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Since it can be slow to make all of these calculations at once, this method will provide a way to get them all back together
|
||||
/// </summary>
|
||||
@@ -578,17 +598,8 @@ namespace MediaBrowser.Controller.Entities
|
||||
return result;
|
||||
}
|
||||
|
||||
foreach (BaseItem item in ActualChildren)
|
||||
{
|
||||
result = item.FindItemById(id);
|
||||
|
||||
if (result != null)
|
||||
{
|
||||
return result;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
//this should be functionally equivilent to what was here since it is IEnum and works on a thread-safe copy
|
||||
return RecursiveChildren.FirstOrDefault(i => i.Id == id);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
@@ -596,31 +607,13 @@ namespace MediaBrowser.Controller.Entities
|
||||
/// </summary>
|
||||
public BaseItem FindByPath(string path)
|
||||
{
|
||||
if (Path.Equals(path, StringComparison.OrdinalIgnoreCase))
|
||||
if (PhysicalLocations.Contains(path, StringComparer.OrdinalIgnoreCase))
|
||||
{
|
||||
return this;
|
||||
}
|
||||
|
||||
foreach (BaseItem item in ActualChildren)
|
||||
{
|
||||
var folder = item as Folder;
|
||||
|
||||
if (folder != null)
|
||||
{
|
||||
var foundItem = folder.FindByPath(path);
|
||||
|
||||
if (foundItem != null)
|
||||
{
|
||||
return foundItem;
|
||||
}
|
||||
}
|
||||
else if (item.Path.Equals(path, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
return item;
|
||||
}
|
||||
}
|
||||
|
||||
return null;
|
||||
//this should be functionally equivilent to what was here since it is IEnum and works on a thread-safe copy
|
||||
return RecursiveChildren.FirstOrDefault(i => i.Path.Equals(path, StringComparison.OrdinalIgnoreCase));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user