The Free Software Media System - Server Backend & API
Apply review suggestions
Shadowghost344a6dcd2c39
diff --git a/Emby.Server.Implementations/IO/LibraryMonitor.cs b/Emby.Server.Implementations/IO/LibraryMonitor.csindex d5735aed27..0f92e2f03e 100644--- a/Emby.Server.Implementations/IO/LibraryMonitor.cs+++ b/Emby.Server.Implementations/IO/LibraryMonitor.cs@@ -368,8 +368,6 @@ namespace Emby.Server.Implementations.IOreturn;}- // The injected service is a singleton, so drop the path before the checks below:- // a change we deliberately do not refresh for still has to read correctly later._directoryService.Invalidate(path);// Ignore certain files, If the parent of an ignored path has a change event, ignore that toodiff --git a/Emby.Server.Implementations/Library/LibraryManager.cs b/Emby.Server.Implementations/Library/LibraryManager.csindex 80e89b4305..dc76e1183e 100644--- a/Emby.Server.Implementations/Library/LibraryManager.cs+++ b/Emby.Server.Implementations/Library/LibraryManager.cs@@ -3723,7 +3723,6 @@ namespace Emby.Server.Implementations.Library}}- // The injected service is a singleton, so its listing predates this folder._directoryService.Invalidate(virtualFolderPath);}finallydiff --git a/Jellyfin.Api/Controllers/LibraryStructureController.cs b/Jellyfin.Api/Controllers/LibraryStructureController.csindex e4833c77dd..65bfe25d21 100644--- a/Jellyfin.Api/Controllers/LibraryStructureController.cs+++ b/Jellyfin.Api/Controllers/LibraryStructureController.cs@@ -183,15 +183,11 @@ public class LibraryStructureController : BaseJellyfinApiControllervar tempPath = Path.Combine(rootFolderPath,Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));- Directory.Move(currentPath, tempPath);+ _directoryService.Move(currentPath, tempPath);currentPath = tempPath;}- Directory.Move(currentPath, newPath);-- // The injected service is a singleton, so its listings of both paths are now stale.- _directoryService.Invalidate(currentPath);- _directoryService.Invalidate(newPath);+ _directoryService.Move(currentPath, newPath);}finally{diff --git a/MediaBrowser.Controller/Providers/DirectoryService.cs b/MediaBrowser.Controller/Providers/DirectoryService.csindex 38872d3cbe..f8e0bf4ed9 100644--- a/MediaBrowser.Controller/Providers/DirectoryService.cs+++ b/MediaBrowser.Controller/Providers/DirectoryService.cs@@ -170,6 +170,14 @@ namespace MediaBrowser.Controller.Providers}}+ public void Move(string source, string destination)+ {+ Directory.Move(source, destination);++ Invalidate(source);+ Invalidate(destination);+ }+public bool IsAccessible(string path){return _fileSystem.GetFileSystemEntryPaths(path).Any();@@ -178,21 +186,21 @@ namespace MediaBrowser.Controller.Providersprivate void DropCacheIfIdleOrFull(){var nowMs = Environment.TickCount64;- var idleMs = nowMs - Volatile.Read(ref _lastAccess);+ var idleMs = nowMs - _lastAccess;- if (idleMs >= IdleTimeoutMs || Volatile.Read(ref _recordCount) >= MaxCachedRecords)+ if (idleMs >= IdleTimeoutMs || _recordCount >= MaxCachedRecords){_cache.Clear();_fileCache.Clear();_filePathCache.Clear();- Volatile.Write(ref _recordCount, 0);- Volatile.Write(ref _lastAccess, nowMs);+ _recordCount = 0;+ _lastAccess = nowMs;return;}if (idleMs >= AccessIntervalMs){- Volatile.Write(ref _lastAccess, nowMs);+ _lastAccess = nowMs;}}diff --git a/MediaBrowser.Controller/Providers/IDirectoryService.cs b/MediaBrowser.Controller/Providers/IDirectoryService.csindex 609d094254..3a943d5f0c 100644--- a/MediaBrowser.Controller/Providers/IDirectoryService.cs+++ b/MediaBrowser.Controller/Providers/IDirectoryService.cs@@ -29,6 +29,13 @@ namespace MediaBrowser.Controller.Providers/// <param name="path">The file or directory path that changed.</param>void Invalidate(string path);+ /// <summary>+ /// Moves a directory and forgets what is cached about both paths.+ /// </summary>+ /// <param name="source">The directory to move.</param>+ /// <param name="destination">The path to move the directory to.</param>+ void Move(string source, string destination);+bool IsAccessible(string path);}}diff --git a/MediaBrowser.Providers/Lyric/LyricManager.cs b/MediaBrowser.Providers/Lyric/LyricManager.csindex dfa7bfde2f..a19262c3a7 100644--- a/MediaBrowser.Providers/Lyric/LyricManager.cs+++ b/MediaBrowser.Providers/Lyric/LyricManager.cs@@ -255,7 +255,6 @@ public class LyricManager : ILyricManager_libraryMonitor.ReportFileSystemChangeComplete(path, false);}- // The injected service is a singleton, so its listing would keep the deleted file._directoryService.Invalidate(path);}@@ -453,7 +452,6 @@ public class LyricManager : ILyricManagerawait stream.CopyToAsync(fs).ConfigureAwait(false);}- // The injected service is a singleton, so its listing of the folder is now stale._directoryService.Invalidate(savePath);return;diff --git a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs b/MediaBrowser.Providers/Subtitles/SubtitleManager.csindex aa363c425f..cd9dda21a0 100644--- a/MediaBrowser.Providers/Subtitles/SubtitleManager.cs+++ b/MediaBrowser.Providers/Subtitles/SubtitleManager.cs@@ -284,7 +284,6 @@ namespace MediaBrowser.Providers.Subtitlesawait stream.CopyToAsync(fs).ConfigureAwait(false);}- // The injected service is a singleton, so its listing of the folder is now stale._directoryService.Invalidate(path);return;@@ -401,7 +400,6 @@ namespace MediaBrowser.Providers.Subtitles_monitor.ReportFileSystemChangeComplete(path, false);}- // The injected service is a singleton, so its listing would keep the deleted file._directoryService.Invalidate(path);return item.RefreshMetadata(CancellationToken.None);