retry image saving to internal location
This commit is contained in:
parent
6271ca99c8
commit
49d222a6d5
|
@ -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);
|
||||
|
|
|
@ -87,6 +87,7 @@ namespace MediaBrowser.Server.Implementations.Channels
|
|||
|
||||
const int currentRefreshLevel = 1;
|
||||
var maxRefreshLevel = features.AutoRefreshLevels ?? 0;
|
||||
maxRefreshLevel = Math.Max(maxRefreshLevel, 2);
|
||||
|
||||
if (maxRefreshLevel > 0)
|
||||
{
|
||||
|
|
|
@ -207,6 +207,8 @@ namespace MediaBrowser.Server.Implementations.Configuration
|
|||
{
|
||||
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
||||
}
|
||||
|
||||
EnsureWriteAccess(newPath);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -227,9 +229,19 @@ namespace MediaBrowser.Server.Implementations.Configuration
|
|||
{
|
||||
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
|
||||
}
|
||||
|
||||
EnsureWriteAccess(newPath);
|
||||
}
|
||||
}
|
||||
|
||||
private void EnsureWriteAccess(string path)
|
||||
{
|
||||
var file = Path.Combine(path, Guid.NewGuid().ToString());
|
||||
|
||||
_fileSystem.WriteAllText(file, string.Empty);
|
||||
_fileSystem.DeleteFile(file);
|
||||
}
|
||||
|
||||
public void DisableMetadataService(string service)
|
||||
{
|
||||
DisableMetadataService(typeof(Movie), Configuration, service);
|
||||
|
|
Loading…
Reference in New Issue
Block a user