|
|
|
@ -123,35 +123,32 @@ namespace MediaBrowser.Providers.Manager
|
|
|
|
|
new[] { GetCacheKeyPath(item, type, mimeType, internalCacheKey) } :
|
|
|
|
|
GetSavePaths(item, type, imageIndex, mimeType, saveLocally);
|
|
|
|
|
|
|
|
|
|
var retryPaths = !string.IsNullOrEmpty(internalCacheKey) ?
|
|
|
|
|
new[] { GetCacheKeyPath(item, type, mimeType, internalCacheKey) } :
|
|
|
|
|
GetSavePaths(item, type, imageIndex, mimeType, false);
|
|
|
|
|
|
|
|
|
|
// If there are more than one output paths, the stream will need to be seekable
|
|
|
|
|
if (paths.Length > 1 && !source.CanSeek)
|
|
|
|
|
{
|
|
|
|
|
var memoryStream = new MemoryStream();
|
|
|
|
|
using (source)
|
|
|
|
|
{
|
|
|
|
|
await source.CopyToAsync(memoryStream).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
memoryStream.Position = 0;
|
|
|
|
|
|
|
|
|
|
source = memoryStream;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
var currentPath = GetCurrentImagePath(item, type, index);
|
|
|
|
|
|
|
|
|
|
using (source)
|
|
|
|
|
{
|
|
|
|
|
var isFirst = true;
|
|
|
|
|
var currentPathIndex = 0;
|
|
|
|
|
|
|
|
|
|
foreach (var path in paths)
|
|
|
|
|
{
|
|
|
|
|
// Seek back to the beginning
|
|
|
|
|
if (!isFirst)
|
|
|
|
|
{
|
|
|
|
|
source.Position = 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
await SaveImageToLocation(source, path, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
await SaveImageToLocation(source, path, retryPaths[currentPathIndex], cancellationToken).ConfigureAwait(false);
|
|
|
|
|
|
|
|
|
|
isFirst = false;
|
|
|
|
|
currentPathIndex++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
@ -185,6 +182,30 @@ namespace MediaBrowser.Providers.Manager
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private async Task SaveImageToLocation(Stream source, string path, string retryPath, CancellationToken cancellationToken)
|
|
|
|
|
{
|
|
|
|
|
try
|
|
|
|
|
{
|
|
|
|
|
await SaveImageToLocation(source, path, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
catch (UnauthorizedAccessException)
|
|
|
|
|
{
|
|
|
|
|
var retry = !string.Equals(path, retryPath, StringComparison.OrdinalIgnoreCase);
|
|
|
|
|
|
|
|
|
|
if (retry)
|
|
|
|
|
{
|
|
|
|
|
_logger.Error("UnauthorizedAccessException - Access to path {0} is denied. Will retry saving to {1}", path, retryPath);
|
|
|
|
|
}
|
|
|
|
|
else
|
|
|
|
|
{
|
|
|
|
|
throw;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
source.Position = 0;
|
|
|
|
|
await SaveImageToLocation(source, retryPath, cancellationToken).ConfigureAwait(false);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private string GetCacheKeyPath(IHasImages item, ImageType type, string mimeType, string key)
|
|
|
|
|
{
|
|
|
|
|
var extension = MimeTypes.ToExtension(mimeType);
|
|
|
|
|