aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/IO
diff options
context:
space:
mode:
authorLogicalPhallacy <44458166+LogicalPhallacy@users.noreply.github.com>2019-02-11 22:48:50 -0800
committerGitHub <noreply@github.com>2019-02-11 22:48:50 -0800
commit8bf88f4cb2ddb140baffd8e4542d8f528b482a67 (patch)
tree5f60f345a22c2468b504b925c0bf4785869185ae /Emby.Server.Implementations/IO
parent4519ce26e2250cb233836296d292ddb7b3cf6346 (diff)
parenteb4b7051676b7493a57a99a821d5dd38bd9d4919 (diff)
Merge pull request #9 from jellyfin/master
Yanking in latest changes
Diffstat (limited to 'Emby.Server.Implementations/IO')
-rw-r--r--Emby.Server.Implementations/IO/FileRefresher.cs14
-rw-r--r--Emby.Server.Implementations/IO/LibraryMonitor.cs31
2 files changed, 23 insertions, 22 deletions
diff --git a/Emby.Server.Implementations/IO/FileRefresher.cs b/Emby.Server.Implementations/IO/FileRefresher.cs
index 12532a497..3668f6a7a 100644
--- a/Emby.Server.Implementations/IO/FileRefresher.cs
+++ b/Emby.Server.Implementations/IO/FileRefresher.cs
@@ -2,6 +2,7 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Threading;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.Library;
@@ -9,7 +10,6 @@ using MediaBrowser.Model.Extensions;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Tasks;
-using MediaBrowser.Model.Threading;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.IO
@@ -22,8 +22,7 @@ namespace Emby.Server.Implementations.IO
private IServerConfigurationManager ConfigurationManager { get; set; }
private readonly IFileSystem _fileSystem;
private readonly List<string> _affectedPaths = new List<string>();
- private ITimer _timer;
- private readonly ITimerFactory _timerFactory;
+ private Timer _timer;
private readonly object _timerLock = new object();
public string Path { get; private set; }
@@ -31,7 +30,7 @@ namespace Emby.Server.Implementations.IO
private readonly IEnvironmentInfo _environmentInfo;
private readonly ILibraryManager _libraryManager;
- public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger, ITimerFactory timerFactory, IEnvironmentInfo environmentInfo, ILibraryManager libraryManager1)
+ public FileRefresher(string path, IFileSystem fileSystem, IServerConfigurationManager configurationManager, ILibraryManager libraryManager, ITaskManager taskManager, ILogger logger, IEnvironmentInfo environmentInfo, ILibraryManager libraryManager1)
{
logger.LogDebug("New file refresher created for {0}", path);
Path = path;
@@ -41,7 +40,6 @@ namespace Emby.Server.Implementations.IO
LibraryManager = libraryManager;
TaskManager = taskManager;
Logger = logger;
- _timerFactory = timerFactory;
_environmentInfo = environmentInfo;
_libraryManager = libraryManager1;
AddPath(path);
@@ -90,7 +88,7 @@ namespace Emby.Server.Implementations.IO
if (_timer == null)
{
- _timer = _timerFactory.Create(OnTimerCallback, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1));
+ _timer = new Timer(OnTimerCallback, null, TimeSpan.FromSeconds(ConfigurationManager.Configuration.LibraryMonitorDelay), TimeSpan.FromMilliseconds(-1));
}
else
{
@@ -146,8 +144,8 @@ namespace Emby.Server.Implementations.IO
.Distinct(StringComparer.OrdinalIgnoreCase)
.Select(GetAffectedBaseItem)
.Where(item => item != null)
- .DistinctBy(i => i.Id)
- .ToList();
+ .GroupBy(x => x.Id)
+ .Select(x => x.First());
foreach (var item in itemsToRefresh)
{
diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.cs
index dad81c195..607a4d333 100644
--- a/Emby.Server.Implementations/IO/LibraryMonitor.cs
+++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs
@@ -11,7 +11,6 @@ using MediaBrowser.Controller.Plugins;
using MediaBrowser.Model.IO;
using MediaBrowser.Model.System;
using MediaBrowser.Model.Tasks;
-using MediaBrowser.Model.Threading;
using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.IO
@@ -35,7 +34,7 @@ namespace Emby.Server.Implementations.IO
/// <summary>
/// Any file name ending in any of these will be ignored by the watchers
/// </summary>
- private readonly string[] _alwaysIgnoreFiles = new string[]
+ private readonly HashSet<string> _alwaysIgnoreFiles = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
"small.jpg",
"albumart.jpg",
@@ -54,7 +53,7 @@ namespace Emby.Server.Implementations.IO
".actors"
};
- private readonly string[] _alwaysIgnoreExtensions = new string[]
+ private readonly HashSet<string> _alwaysIgnoreExtensions = new HashSet<string>(StringComparer.OrdinalIgnoreCase)
{
// thumbs.db
".db",
@@ -134,7 +133,6 @@ namespace Emby.Server.Implementations.IO
private IServerConfigurationManager ConfigurationManager { get; set; }
private readonly IFileSystem _fileSystem;
- private readonly ITimerFactory _timerFactory;
private readonly IEnvironmentInfo _environmentInfo;
/// <summary>
@@ -146,7 +144,6 @@ namespace Emby.Server.Implementations.IO
ILibraryManager libraryManager,
IServerConfigurationManager configurationManager,
IFileSystem fileSystem,
- ITimerFactory timerFactory,
IEnvironmentInfo environmentInfo)
{
if (taskManager == null)
@@ -159,7 +156,6 @@ namespace Emby.Server.Implementations.IO
Logger = loggerFactory.CreateLogger(GetType().Name);
ConfigurationManager = configurationManager;
_fileSystem = fileSystem;
- _timerFactory = timerFactory;
_environmentInfo = environmentInfo;
}
@@ -460,8 +456,8 @@ namespace Emby.Server.Implementations.IO
var filename = Path.GetFileName(path);
var monitorPath = !string.IsNullOrEmpty(filename) &&
- !_alwaysIgnoreFiles.Contains(filename, StringComparer.OrdinalIgnoreCase) &&
- !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path) ?? string.Empty, StringComparer.OrdinalIgnoreCase) &&
+ !_alwaysIgnoreFiles.Contains(filename) &&
+ !_alwaysIgnoreExtensions.Contains(Path.GetExtension(path)) &&
_alwaysIgnoreSubstrings.All(i => path.IndexOf(i, StringComparison.OrdinalIgnoreCase) == -1);
// Ignore certain files
@@ -545,7 +541,7 @@ namespace Emby.Server.Implementations.IO
}
}
- var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger, _timerFactory, _environmentInfo, LibraryManager);
+ var newRefresher = new FileRefresher(path, _fileSystem, ConfigurationManager, LibraryManager, TaskManager, Logger, _environmentInfo, LibraryManager);
newRefresher.Completed += NewRefresher_Completed;
_activeRefreshers.Add(newRefresher);
}
@@ -601,20 +597,26 @@ namespace Emby.Server.Implementations.IO
/// </summary>
public void Dispose()
{
- _disposed = true;
Dispose(true);
}
/// <summary>
/// Releases unmanaged and - optionally - managed resources.
/// </summary>
- /// <param name="dispose"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
- protected virtual void Dispose(bool dispose)
+ /// <param name="disposing"><c>true</c> to release both managed and unmanaged resources; <c>false</c> to release only unmanaged resources.</param>
+ protected virtual void Dispose(bool disposing)
{
- if (dispose)
+ if (_disposed)
+ {
+ return;
+ }
+
+ if (disposing)
{
Stop();
}
+
+ _disposed = true;
}
}
@@ -627,9 +629,10 @@ namespace Emby.Server.Implementations.IO
_monitor = monitor;
}
- public void Run()
+ public Task RunAsync()
{
_monitor.Start();
+ return Task.CompletedTask;
}
public void Dispose()