mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-04-24 14:08:44 -04:00
chore: use proper way to override remove root
This is an alternate approach which is more proper, but changes all parts that uses/overrides the original ValidateChildren method Signed-off-by: gnattu <gnattuoc@me.com>
This commit is contained in:
parent
7befbda1a6
commit
e4d66f35fd
9 changed files with 27 additions and 31 deletions
|
@ -1042,26 +1042,16 @@ namespace Emby.Server.Implementations.Library
|
||||||
new Progress<double>(),
|
new Progress<double>(),
|
||||||
new MetadataRefreshOptions(new DirectoryService(_fileSystem)),
|
new MetadataRefreshOptions(new DirectoryService(_fileSystem)),
|
||||||
recursive: false,
|
recursive: false,
|
||||||
cancellationToken).ConfigureAwait(false);
|
cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
await GetUserRootFolder().RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
await GetUserRootFolder().RefreshMetadata(cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
// HACK: override IsRoot here for libraries to be removed
|
|
||||||
if (removeRoot)
|
|
||||||
{
|
|
||||||
GetUserRootFolder().IsRoot = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
await GetUserRootFolder().ValidateChildren(
|
await GetUserRootFolder().ValidateChildren(
|
||||||
new Progress<double>(),
|
new Progress<double>(),
|
||||||
new MetadataRefreshOptions(new DirectoryService(_fileSystem)),
|
new MetadataRefreshOptions(new DirectoryService(_fileSystem)),
|
||||||
recursive: false,
|
recursive: false,
|
||||||
cancellationToken).ConfigureAwait(false);
|
allowRemoveRoot: removeRoot,
|
||||||
// HACK: restore IsRoot here after validation
|
cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
if (removeRoot)
|
|
||||||
{
|
|
||||||
GetUserRootFolder().IsRoot = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
// Quickly scan CollectionFolders for changes
|
// Quickly scan CollectionFolders for changes
|
||||||
foreach (var folder in GetUserRootFolder().Children.OfType<Folder>())
|
foreach (var folder in GetUserRootFolder().Children.OfType<Folder>())
|
||||||
|
@ -1079,7 +1069,7 @@ namespace Emby.Server.Implementations.Library
|
||||||
var innerProgress = new Progress<double>(pct => progress.Report(pct * 0.96));
|
var innerProgress = new Progress<double>(pct => progress.Report(pct * 0.96));
|
||||||
|
|
||||||
// Validate the entire media library
|
// Validate the entire media library
|
||||||
await RootFolder.ValidateChildren(innerProgress, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), recursive: true, cancellationToken).ConfigureAwait(false);
|
await RootFolder.ValidateChildren(innerProgress, new MetadataRefreshOptions(new DirectoryService(_fileSystem)), recursive: true, cancellationToken: cancellationToken).ConfigureAwait(false);
|
||||||
|
|
||||||
progress.Report(96);
|
progress.Report(96);
|
||||||
|
|
||||||
|
|
|
@ -155,11 +155,11 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return base.GetNonCachedChildren(directoryService).Concat(_virtualChildren);
|
return base.GetNonCachedChildren(directoryService).Concat(_virtualChildren);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
ClearCache();
|
ClearCache();
|
||||||
|
|
||||||
await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, refreshOptions, directoryService, cancellationToken)
|
await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, false, refreshOptions, directoryService, cancellationToken)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
ClearCache();
|
ClearCache();
|
||||||
|
|
|
@ -110,7 +110,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||||
return base.IsSaveLocalMetadataEnabled();
|
return base.IsSaveLocalMetadataEnabled();
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (IsAccessedByName)
|
if (IsAccessedByName)
|
||||||
{
|
{
|
||||||
|
@ -118,7 +118,7 @@ namespace MediaBrowser.Controller.Entities.Audio
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
||||||
return base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, refreshOptions, directoryService, cancellationToken);
|
return base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, false, refreshOptions, directoryService, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
public override List<string> GetUserDataKeys()
|
public override List<string> GetUserDataKeys()
|
||||||
|
|
|
@ -316,11 +316,12 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <param name="progress">The progress.</param>
|
/// <param name="progress">The progress.</param>
|
||||||
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
||||||
/// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
|
/// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
|
||||||
|
/// <param name="allowRemoveRoot">remove item even this folder is root.</param>
|
||||||
/// <param name="refreshOptions">The refresh options.</param>
|
/// <param name="refreshOptions">The refresh options.</param>
|
||||||
/// <param name="directoryService">The directory service.</param>
|
/// <param name="directoryService">The directory service.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
|
@ -269,11 +269,12 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <param name="progress">The progress.</param>
|
/// <param name="progress">The progress.</param>
|
||||||
/// <param name="metadataRefreshOptions">The metadata refresh options.</param>
|
/// <param name="metadataRefreshOptions">The metadata refresh options.</param>
|
||||||
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
||||||
|
/// <param name="allowRemoveRoot">remove item even this folder is root.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
public Task ValidateChildren(IProgress<double> progress, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true, CancellationToken cancellationToken = default)
|
public Task ValidateChildren(IProgress<double> progress, MetadataRefreshOptions metadataRefreshOptions, bool recursive = true, bool allowRemoveRoot = false, CancellationToken cancellationToken = default)
|
||||||
{
|
{
|
||||||
return ValidateChildrenInternal(progress, recursive, true, metadataRefreshOptions, metadataRefreshOptions.DirectoryService, cancellationToken);
|
return ValidateChildrenInternal(progress, recursive, true, false, metadataRefreshOptions, metadataRefreshOptions.DirectoryService, cancellationToken);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Dictionary<Guid, BaseItem> GetActualChildrenDictionary()
|
private Dictionary<Guid, BaseItem> GetActualChildrenDictionary()
|
||||||
|
@ -307,11 +308,12 @@ namespace MediaBrowser.Controller.Entities
|
||||||
/// <param name="progress">The progress.</param>
|
/// <param name="progress">The progress.</param>
|
||||||
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
/// <param name="recursive">if set to <c>true</c> [recursive].</param>
|
||||||
/// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
|
/// <param name="refreshChildMetadata">if set to <c>true</c> [refresh child metadata].</param>
|
||||||
|
/// <param name="allowRemoveRoot">remove item even this folder is root.</param>
|
||||||
/// <param name="refreshOptions">The refresh options.</param>
|
/// <param name="refreshOptions">The refresh options.</param>
|
||||||
/// <param name="directoryService">The directory service.</param>
|
/// <param name="directoryService">The directory service.</param>
|
||||||
/// <param name="cancellationToken">The cancellation token.</param>
|
/// <param name="cancellationToken">The cancellation token.</param>
|
||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
protected virtual async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
protected virtual async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (recursive)
|
if (recursive)
|
||||||
{
|
{
|
||||||
|
@ -320,7 +322,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
await ValidateChildrenInternal2(progress, recursive, refreshChildMetadata, refreshOptions, directoryService, cancellationToken).ConfigureAwait(false);
|
await ValidateChildrenInternal2(progress, recursive, refreshChildMetadata, allowRemoveRoot, refreshOptions, directoryService, cancellationToken).ConfigureAwait(false);
|
||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
|
@ -343,7 +345,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
private async Task ValidateChildrenInternal2(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
private async Task ValidateChildrenInternal2(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
if (!IsLibraryFolderAccessible(directoryService, this))
|
if (!IsLibraryFolderAccessible(directoryService, this))
|
||||||
{
|
{
|
||||||
|
@ -414,8 +416,9 @@ namespace MediaBrowser.Controller.Entities
|
||||||
validChildren.Add(child);
|
validChildren.Add(child);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
var shouldNotRemove = IsRoot && !allowRemoveRoot;
|
||||||
// If it's an AggregateFolder, don't remove
|
// If it's an AggregateFolder, don't remove
|
||||||
if (!IsRoot && currentChildren.Count != validChildren.Count)
|
if (shouldNotRemove && currentChildren.Count != validChildren.Count)
|
||||||
{
|
{
|
||||||
// That's all the new and changed ones - now see if there are any that are missing
|
// That's all the new and changed ones - now see if there are any that are missing
|
||||||
var itemsRemoved = currentChildren.Values.Except(validChildren).ToList();
|
var itemsRemoved = currentChildren.Values.Except(validChildren).ToList();
|
||||||
|
@ -562,7 +565,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
private Task ValidateSubFolders(IList<Folder> children, IDirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken)
|
private Task ValidateSubFolders(IList<Folder> children, IDirectoryService directoryService, IProgress<double> progress, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return RunTasks(
|
return RunTasks(
|
||||||
(folder, innerProgress) => folder.ValidateChildrenInternal(innerProgress, true, false, null, directoryService, cancellationToken),
|
(folder, innerProgress) => folder.ValidateChildrenInternal(innerProgress, true, false, false, null, directoryService, cancellationToken),
|
||||||
children,
|
children,
|
||||||
progress,
|
progress,
|
||||||
cancellationToken);
|
cancellationToken);
|
||||||
|
|
|
@ -117,11 +117,11 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return base.GetNonCachedChildren(directoryService);
|
return base.GetNonCachedChildren(directoryService);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
protected override async Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
ClearCache();
|
ClearCache();
|
||||||
|
|
||||||
await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, refreshOptions, directoryService, cancellationToken)
|
await base.ValidateChildrenInternal(progress, recursive, refreshChildMetadata, false, refreshOptions, directoryService, cancellationToken)
|
||||||
.ConfigureAwait(false);
|
.ConfigureAwait(false);
|
||||||
|
|
||||||
ClearCache();
|
ClearCache();
|
||||||
|
|
|
@ -6,10 +6,12 @@ using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text.Json.Serialization;
|
using System.Text.Json.Serialization;
|
||||||
|
using System.Threading;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
using Jellyfin.Data.Entities;
|
using Jellyfin.Data.Entities;
|
||||||
using Jellyfin.Data.Enums;
|
using Jellyfin.Data.Enums;
|
||||||
using Jellyfin.Extensions;
|
using Jellyfin.Extensions;
|
||||||
|
using MediaBrowser.Controller.Providers;
|
||||||
using MediaBrowser.Controller.TV;
|
using MediaBrowser.Controller.TV;
|
||||||
using MediaBrowser.Model.Querying;
|
using MediaBrowser.Model.Querying;
|
||||||
|
|
||||||
|
@ -180,7 +182,7 @@ namespace MediaBrowser.Controller.Entities
|
||||||
return _originalFolderViewTypes.Contains(viewType);
|
return _originalFolderViewTypes.Contains(viewType);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, Providers.MetadataRefreshOptions refreshOptions, Providers.IDirectoryService directoryService, System.Threading.CancellationToken cancellationToken)
|
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
|
@ -132,7 +132,7 @@ namespace MediaBrowser.Controller.Playlists
|
||||||
return [];
|
return [];
|
||||||
}
|
}
|
||||||
|
|
||||||
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
protected override Task ValidateChildrenInternal(IProgress<double> progress, bool recursive, bool refreshChildMetadata, bool allowRemoveRoot, MetadataRefreshOptions refreshOptions, IDirectoryService directoryService, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
return Task.CompletedTask;
|
return Task.CompletedTask;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1106,7 +1106,7 @@ namespace MediaBrowser.Providers.Manager
|
||||||
.Where(i => i is not null)
|
.Where(i => i is not null)
|
||||||
.Distinct();
|
.Distinct();
|
||||||
|
|
||||||
var musicArtistRefreshTasks = musicArtists.Select(i => i.ValidateChildren(new Progress<double>(), options, true, cancellationToken));
|
var musicArtistRefreshTasks = musicArtists.Select(i => i.ValidateChildren(new Progress<double>(), options, true, false, cancellationToken));
|
||||||
|
|
||||||
await Task.WhenAll(musicArtistRefreshTasks).ConfigureAwait(false);
|
await Task.WhenAll(musicArtistRefreshTasks).ConfigureAwait(false);
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue