@ -9,6 +9,7 @@ using System.Collections.Generic;
using System.Linq ;
using System.Linq ;
using System.Threading ;
using System.Threading ;
using System.Threading.Tasks ;
using System.Threading.Tasks ;
using MediaBrowser.Common.Configuration ;
using MediaBrowser.Model.IO ;
using MediaBrowser.Model.IO ;
using MediaBrowser.Controller.Channels ;
using MediaBrowser.Controller.Channels ;
using MediaBrowser.Controller.Entities.Audio ;
using MediaBrowser.Controller.Entities.Audio ;
@ -22,13 +23,15 @@ namespace Emby.Server.Implementations.Data
private readonly IItemRepository _itemRepo ;
private readonly IItemRepository _itemRepo ;
private readonly ILogger _logger ;
private readonly ILogger _logger ;
private readonly IFileSystem _fileSystem ;
private readonly IFileSystem _fileSystem ;
private readonly IApplicationPaths _appPaths ;
public CleanDatabaseScheduledTask ( ILibraryManager libraryManager , IItemRepository itemRepo , ILogger logger , IFileSystem fileSystem )
public CleanDatabaseScheduledTask ( ILibraryManager libraryManager , IItemRepository itemRepo , ILogger logger , IFileSystem fileSystem , IApplicationPaths appPaths )
{
{
_libraryManager = libraryManager ;
_libraryManager = libraryManager ;
_itemRepo = itemRepo ;
_itemRepo = itemRepo ;
_logger = logger ;
_logger = logger ;
_fileSystem = fileSystem ;
_fileSystem = fileSystem ;
_appPaths = appPaths ;
}
}
public string Name
public string Name
@ -150,13 +153,27 @@ namespace Emby.Server.Implementations.Data
try
try
{
{
var isPathInLibrary = false ;
if ( allLibraryPaths . Any ( i = > path . StartsWith ( i , StringComparison . Ordinal ) ) | |
allLibraryPaths . Contains ( path , StringComparer . Ordinal ) | |
path . StartsWith ( _appPaths . ProgramDataPath , StringComparison . Ordinal ) )
{
isPathInLibrary = true ;
if ( _fileSystem . FileExists ( path ) | | _fileSystem . DirectoryExists ( path ) )
if ( _fileSystem . FileExists ( path ) | | _fileSystem . DirectoryExists ( path ) )
{
{
continue ;
continue ;
}
}
}
var libraryItem = _libraryManager . GetItemById ( item . Item1 ) ;
var libraryItem = _libraryManager . GetItemById ( item . Item1 ) ;
if ( libraryItem = = null )
{
continue ;
}
if ( libraryItem . IsTopParent )
if ( libraryItem . IsTopParent )
{
{
continue ;
continue ;
@ -180,7 +197,14 @@ namespace Emby.Server.Implementations.Data
continue ;
continue ;
}
}
if ( isPathInLibrary )
{
_logger . Info ( "Deleting item from database {0} because path no longer exists. type: {1} path: {2}" , libraryItem . Name , libraryItem . GetType ( ) . Name , libraryItemPath ? ? string . Empty ) ;
_logger . Info ( "Deleting item from database {0} because path no longer exists. type: {1} path: {2}" , libraryItem . Name , libraryItem . GetType ( ) . Name , libraryItemPath ? ? string . Empty ) ;
}
else
{
_logger . Info ( "Deleting item from database {0} because path is no longer in the server library. type: {1} path: {2}" , libraryItem . Name , libraryItem . GetType ( ) . Name , libraryItemPath ? ? string . Empty ) ;
}
await libraryItem . OnFileDeleted ( ) . ConfigureAwait ( false ) ;
await libraryItem . OnFileDeleted ( ) . ConfigureAwait ( false ) ;
}
}