mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-04-21 01:24:44 +01:00
re-factored some file system access
This commit is contained in:
@@ -168,6 +168,14 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
if (!success)
|
||||
{
|
||||
previouslyFailedImages.Add(key);
|
||||
|
||||
var parentPath = Path.GetDirectoryName(failHistoryPath);
|
||||
|
||||
if (!Directory.Exists(parentPath))
|
||||
{
|
||||
Directory.CreateDirectory(parentPath);
|
||||
}
|
||||
|
||||
_jsonSerializer.SerializeToFile(previouslyFailedImages, failHistoryPath);
|
||||
}
|
||||
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
var specialFeattures = _itemRepo.GetItems(movie.SpecialFeatureIds).ToList();
|
||||
images = specialFeattures.Aggregate(images, (current, subItem) => current.Concat(GetPathsInUse(subItem)));
|
||||
}
|
||||
|
||||
|
||||
return images;
|
||||
}
|
||||
|
||||
@@ -176,13 +176,20 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
/// <returns>IEnumerable{System.String}.</returns>
|
||||
private IEnumerable<string> GetFiles(string path)
|
||||
{
|
||||
return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
|
||||
.Where(i =>
|
||||
{
|
||||
var ext = Path.GetExtension(i);
|
||||
try
|
||||
{
|
||||
return Directory.EnumerateFiles(path, "*", SearchOption.AllDirectories)
|
||||
.Where(i =>
|
||||
{
|
||||
var ext = Path.GetExtension(i);
|
||||
|
||||
return !string.IsNullOrEmpty(ext) && BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
|
||||
});
|
||||
return !string.IsNullOrEmpty(ext) && BaseItem.SupportedImageExtensions.Contains(ext, StringComparer.OrdinalIgnoreCase);
|
||||
});
|
||||
}
|
||||
catch (DirectoryNotFoundException)
|
||||
{
|
||||
return new string[] { };
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
||||
@@ -8,14 +8,15 @@ using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Controller.Providers.MediaInfo;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MoreLinq;
|
||||
using System;
|
||||
using System.Collections.Concurrent;
|
||||
using System.Collections.Generic;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using MoreLinq;
|
||||
|
||||
namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
{
|
||||
@@ -263,7 +264,7 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
|
||||
var path = ImageCache.GetResourcePath(filename, ".jpg");
|
||||
|
||||
if (!ImageCache.ContainsFilePath(path))
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
var semaphore = GetLock(path);
|
||||
|
||||
@@ -271,10 +272,17 @@ namespace MediaBrowser.Server.Implementations.ScheduledTasks
|
||||
await semaphore.WaitAsync(cancellationToken).ConfigureAwait(false);
|
||||
|
||||
// Check again
|
||||
if (!ImageCache.ContainsFilePath(path))
|
||||
if (!File.Exists(path))
|
||||
{
|
||||
try
|
||||
{
|
||||
var parentPath = Path.GetDirectoryName(path);
|
||||
|
||||
if (!Directory.Exists(parentPath))
|
||||
{
|
||||
Directory.CreateDirectory(parentPath);
|
||||
}
|
||||
|
||||
await ExtractImageInternal(item, path, cancellationToken).ConfigureAwait(false);
|
||||
}
|
||||
finally
|
||||
|
||||
Reference in New Issue
Block a user