mirror of
https://github.com/jellyfin/jellyfin.git
synced 2025-05-31 20:24:21 -04:00
Clean up synchronization (#11458)
This commit is contained in:
parent
688a734895
commit
af74aa35d7
@ -247,7 +247,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
|||||||
MediaSourceInfo mediaSource,
|
MediaSourceInfo mediaSource,
|
||||||
CancellationToken cancellationToken)
|
CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var outputFileLocks = new List<AsyncKeyedLockReleaser<string>>();
|
var outputFileLocks = new List<IDisposable>();
|
||||||
var extractableAttachmentIds = new List<int>();
|
var extractableAttachmentIds = new List<int>();
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -256,16 +256,15 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
|||||||
{
|
{
|
||||||
var outputPath = GetAttachmentCachePath(mediaPath, mediaSource, attachment.Index);
|
var outputPath = GetAttachmentCachePath(mediaPath, mediaSource, attachment.Index);
|
||||||
|
|
||||||
var @outputFileLock = _semaphoreLocks.GetOrAdd(outputPath);
|
var releaser = await _semaphoreLocks.LockAsync(outputPath, cancellationToken).ConfigureAwait(false);
|
||||||
await @outputFileLock.SemaphoreSlim.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (File.Exists(outputPath))
|
if (File.Exists(outputPath))
|
||||||
{
|
{
|
||||||
@outputFileLock.Dispose();
|
releaser.Dispose();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
outputFileLocks.Add(@outputFileLock);
|
outputFileLocks.Add(releaser);
|
||||||
extractableAttachmentIds.Add(attachment.Index);
|
extractableAttachmentIds.Add(attachment.Index);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -280,10 +279,7 @@ namespace MediaBrowser.MediaEncoding.Attachments
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
foreach (var @outputFileLock in outputFileLocks)
|
outputFileLocks.ForEach(x => x.Dispose());
|
||||||
{
|
|
||||||
@outputFileLock.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -457,7 +457,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||||||
/// <returns>Task.</returns>
|
/// <returns>Task.</returns>
|
||||||
private async Task ExtractAllTextSubtitles(MediaSourceInfo mediaSource, CancellationToken cancellationToken)
|
private async Task ExtractAllTextSubtitles(MediaSourceInfo mediaSource, CancellationToken cancellationToken)
|
||||||
{
|
{
|
||||||
var locks = new List<AsyncKeyedLockReleaser<string>>();
|
var locks = new List<IDisposable>();
|
||||||
var extractableStreams = new List<MediaStream>();
|
var extractableStreams = new List<MediaStream>();
|
||||||
|
|
||||||
try
|
try
|
||||||
@ -469,16 +469,15 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||||||
{
|
{
|
||||||
var outputPath = GetSubtitleCachePath(mediaSource, subtitleStream.Index, "." + GetTextSubtitleFormat(subtitleStream));
|
var outputPath = GetSubtitleCachePath(mediaSource, subtitleStream.Index, "." + GetTextSubtitleFormat(subtitleStream));
|
||||||
|
|
||||||
var @lock = _semaphoreLocks.GetOrAdd(outputPath);
|
var releaser = await _semaphoreLocks.LockAsync(outputPath, cancellationToken).ConfigureAwait(false);
|
||||||
await @lock.SemaphoreSlim.WaitAsync(cancellationToken).ConfigureAwait(false);
|
|
||||||
|
|
||||||
if (File.Exists(outputPath))
|
if (File.Exists(outputPath))
|
||||||
{
|
{
|
||||||
@lock.Dispose();
|
releaser.Dispose();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
locks.Add(@lock);
|
locks.Add(releaser);
|
||||||
extractableStreams.Add(subtitleStream);
|
extractableStreams.Add(subtitleStream);
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -493,10 +492,7 @@ namespace MediaBrowser.MediaEncoding.Subtitles
|
|||||||
}
|
}
|
||||||
finally
|
finally
|
||||||
{
|
{
|
||||||
foreach (var @lock in locks)
|
locks.ForEach(x => x.Dispose());
|
||||||
{
|
|
||||||
@lock.Dispose();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user