mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-05-13 08:37:07 +00:00
Fix use of thread-unsafe List<T>.Sort()
This commit is contained in:
parent
ec04313317
commit
6f2e42c20c
4 changed files with 16 additions and 21 deletions
|
|
@ -105,7 +105,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
public IReadOnlyList<string> GetFilePaths(string path)
|
||||
=> GetFilePaths(path, false);
|
||||
|
||||
public IReadOnlyList<string> GetFilePaths(string path, bool clearCache, bool sort = false)
|
||||
public IReadOnlyList<string> GetFilePaths(string path, bool clearCache)
|
||||
{
|
||||
if (clearCache)
|
||||
{
|
||||
|
|
@ -118,7 +118,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
{
|
||||
try
|
||||
{
|
||||
return fileSystem.GetFilePaths(p).ToList();
|
||||
return fileSystem.GetFilePaths(p).OrderBy(x => x).ToList();
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
|
|
@ -127,11 +127,6 @@ namespace MediaBrowser.Controller.Providers
|
|||
},
|
||||
_fileSystem);
|
||||
|
||||
if (sort)
|
||||
{
|
||||
filePaths.Sort();
|
||||
}
|
||||
|
||||
return filePaths;
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -21,7 +21,7 @@ namespace MediaBrowser.Controller.Providers
|
|||
|
||||
IReadOnlyList<string> GetFilePaths(string path);
|
||||
|
||||
IReadOnlyList<string> GetFilePaths(string path, bool clearCache, bool sort = false);
|
||||
IReadOnlyList<string> GetFilePaths(string path, bool clearCache);
|
||||
|
||||
bool IsAccessible(string path);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -218,12 +218,12 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
return Array.Empty<ExternalPathParserResult>();
|
||||
}
|
||||
|
||||
var files = directoryService.GetFilePaths(folder, clearCache, true).ToList();
|
||||
var files = directoryService.GetFilePaths(folder, clearCache).ToList();
|
||||
files.Remove(video.Path);
|
||||
var internalMetadataPath = video.GetInternalMetadataPath();
|
||||
if (_fileSystem.DirectoryExists(internalMetadataPath))
|
||||
{
|
||||
files.AddRange(directoryService.GetFilePaths(internalMetadataPath, clearCache, true));
|
||||
files.AddRange(directoryService.GetFilePaths(internalMetadataPath, clearCache));
|
||||
}
|
||||
|
||||
if (files.Count == 0)
|
||||
|
|
@ -270,12 +270,12 @@ namespace MediaBrowser.Providers.MediaInfo
|
|||
}
|
||||
|
||||
string folder = audio.ContainingFolderPath;
|
||||
var files = directoryService.GetFilePaths(folder, clearCache, true).ToList();
|
||||
var files = directoryService.GetFilePaths(folder, clearCache).ToList();
|
||||
files.Remove(audio.Path);
|
||||
var internalMetadataPath = audio.GetInternalMetadataPath();
|
||||
if (_fileSystem.DirectoryExists(internalMetadataPath))
|
||||
{
|
||||
files.AddRange(directoryService.GetFilePaths(internalMetadataPath, clearCache, true));
|
||||
files.AddRange(directoryService.GetFilePaths(internalMetadataPath, clearCache));
|
||||
}
|
||||
|
||||
if (files.Count == 0)
|
||||
|
|
|
|||
|
|
@ -123,13 +123,13 @@ public class MediaInfoResolverTests
|
|||
|
||||
var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
|
||||
// any path other than test target exists and provides an empty listing
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(Array.Empty<string>());
|
||||
|
||||
_subtitleResolver.GetExternalFiles(video.Object, directoryService.Object, false);
|
||||
|
||||
directoryService.Verify(
|
||||
ds => ds.GetFilePaths(It.IsRegex(pathNotFoundRegex), It.IsAny<bool>(), It.IsAny<bool>()),
|
||||
ds => ds.GetFilePaths(It.IsRegex(pathNotFoundRegex), It.IsAny<bool>()),
|
||||
Times.Never);
|
||||
}
|
||||
|
||||
|
|
@ -196,7 +196,7 @@ public class MediaInfoResolverTests
|
|||
};
|
||||
|
||||
var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsAny<string>(), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsAny<string>(), It.IsAny<bool>()))
|
||||
.Returns(Array.Empty<string>());
|
||||
|
||||
var mediaEncoder = Mock.Of<IMediaEncoder>(MockBehavior.Strict);
|
||||
|
|
@ -341,9 +341,9 @@ public class MediaInfoResolverTests
|
|||
}
|
||||
|
||||
var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(VideoDirectoryRegex), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(VideoDirectoryRegex), It.IsAny<bool>()))
|
||||
.Returns(files);
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(MetadataDirectoryRegex), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(MetadataDirectoryRegex), It.IsAny<bool>()))
|
||||
.Returns(Array.Empty<string>());
|
||||
|
||||
List<MediaStream> GenerateMediaStreams()
|
||||
|
|
@ -413,16 +413,16 @@ public class MediaInfoResolverTests
|
|||
var directoryService = new Mock<IDirectoryService>(MockBehavior.Strict);
|
||||
if (useMetadataDirectory)
|
||||
{
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(VideoDirectoryRegex), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(VideoDirectoryRegex), It.IsAny<bool>()))
|
||||
.Returns(Array.Empty<string>());
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(MetadataDirectoryRegex), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(MetadataDirectoryRegex), It.IsAny<bool>()))
|
||||
.Returns(new[] { MetadataDirectoryPath + "/" + file });
|
||||
}
|
||||
else
|
||||
{
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(VideoDirectoryRegex), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(VideoDirectoryRegex), It.IsAny<bool>()))
|
||||
.Returns(new[] { VideoDirectoryPath + "/" + file });
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(MetadataDirectoryRegex), It.IsAny<bool>(), It.IsAny<bool>()))
|
||||
directoryService.Setup(ds => ds.GetFilePaths(It.IsRegex(MetadataDirectoryRegex), It.IsAny<bool>()))
|
||||
.Returns(Array.Empty<string>());
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue