diff options
| author | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-03-13 14:58:00 -0400 |
|---|---|---|
| committer | Luke Pulverenti <luke.pulverenti@gmail.com> | 2017-03-13 14:58:00 -0400 |
| commit | 203fc64a9752f50989a04d4c6c173fe13a9dcd14 (patch) | |
| tree | 589812e66dd6bb787bc0e7b23fc4f73220d85d3b | |
| parent | a8fc4804893cb1ca8d54cd85019f53f621b97e91 (diff) | |
improve clean db task
| -rw-r--r-- | Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs | 32 |
1 files changed, 28 insertions, 4 deletions
diff --git a/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs b/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs index 2819a249f..0096f2284 100644 --- a/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs +++ b/Emby.Server.Implementations/Data/CleanDatabaseScheduledTask.cs @@ -9,6 +9,7 @@ using System.Collections.Generic; using System.Linq; using System.Threading; using System.Threading.Tasks; +using MediaBrowser.Common.Configuration; using MediaBrowser.Model.IO; using MediaBrowser.Controller.Channels; using MediaBrowser.Controller.Entities.Audio; @@ -22,13 +23,15 @@ namespace Emby.Server.Implementations.Data private readonly IItemRepository _itemRepo; private readonly ILogger _logger; 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; _itemRepo = itemRepo; _logger = logger; _fileSystem = fileSystem; + _appPaths = appPaths; } public string Name @@ -150,13 +153,27 @@ namespace Emby.Server.Implementations.Data try { - if (_fileSystem.FileExists(path) || _fileSystem.DirectoryExists(path)) + var isPathInLibrary = false; + + if (allLibraryPaths.Any(i => path.StartsWith(i, StringComparison.Ordinal)) || + allLibraryPaths.Contains(path, StringComparer.Ordinal) || + path.StartsWith(_appPaths.ProgramDataPath, StringComparison.Ordinal)) { - continue; + isPathInLibrary = true; + + if (_fileSystem.FileExists(path) || _fileSystem.DirectoryExists(path)) + { + continue; + } } var libraryItem = _libraryManager.GetItemById(item.Item1); + if (libraryItem == null) + { + continue; + } + if (libraryItem.IsTopParent) { continue; @@ -180,7 +197,14 @@ namespace Emby.Server.Implementations.Data continue; } - _logger.Info("Deleting item from database {0} because path no longer exists. type: {1} path: {2}", libraryItem.Name, libraryItem.GetType().Name, libraryItemPath ?? string.Empty); + 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); + } + 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); } |
