|
@@ -7,6 +7,7 @@ using System.Linq;
|
|
|
using System.Net;
|
|
|
using System.Net.Http;
|
|
|
using System.Net.Mime;
|
|
|
+using System.Runtime.ExceptionServices;
|
|
|
using System.Threading;
|
|
|
using System.Threading.Tasks;
|
|
|
using AsyncKeyedLock;
|
|
@@ -251,15 +252,29 @@ namespace MediaBrowser.Providers.Manager
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|
|
|
- public Task SaveImage(BaseItem item, string source, string mimeType, ImageType type, int? imageIndex, bool? saveLocallyWithMedia, CancellationToken cancellationToken)
|
|
|
+ public async Task SaveImage(BaseItem item, string source, string mimeType, ImageType type, int? imageIndex, bool? saveLocallyWithMedia, CancellationToken cancellationToken)
|
|
|
{
|
|
|
if (string.IsNullOrWhiteSpace(source))
|
|
|
{
|
|
|
throw new ArgumentNullException(nameof(source));
|
|
|
}
|
|
|
|
|
|
- var fileStream = AsyncFile.OpenRead(source);
|
|
|
- return new ImageSaver(_configurationManager, _libraryMonitor, _fileSystem, _logger).SaveImage(item, fileStream, mimeType, type, imageIndex, saveLocallyWithMedia, cancellationToken);
|
|
|
+ try
|
|
|
+ {
|
|
|
+ var fileStream = AsyncFile.OpenRead(source);
|
|
|
+ await new ImageSaver(_configurationManager, _libraryMonitor, _fileSystem, _logger).SaveImage(item, fileStream, mimeType, type, imageIndex, saveLocallyWithMedia, cancellationToken);
|
|
|
+ }
|
|
|
+ finally
|
|
|
+ {
|
|
|
+ try
|
|
|
+ {
|
|
|
+ File.Delete(source);
|
|
|
+ }
|
|
|
+ catch (Exception ex)
|
|
|
+ {
|
|
|
+ _logger.LogError(ex, "Source file {Source} not found or in use, skip removing", source);
|
|
|
+ }
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
/// <inheritdoc/>
|