#200 - MB3 Locking Folders for a long time

This commit is contained in:
Luke Pulverenti 2013-04-27 20:44:38 -04:00
parent e744302709
commit 90bb3d46c4
5 changed files with 87 additions and 46 deletions

View File

@ -78,16 +78,6 @@ namespace MediaBrowser.Controller.IO
return GetFileSystemEntries(path, searchPattern, includeDirectories: false);
}
/// <summary>
/// Gets all sub-directories within a folder
/// </summary>
/// <param name="path">The path.</param>
/// <returns>IEnumerable{WIN32_FIND_DATA}.</returns>
public static IEnumerable<WIN32_FIND_DATA> GetDirectories(string path)
{
return GetFileSystemEntries(path, includeFiles: false);
}
/// <summary>
/// Gets all file system entries within a foler
/// </summary>

View File

@ -1,13 +1,12 @@
using System.Threading;
using System.Threading.Tasks;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Configuration;
using MediaBrowser.Controller.Entities;
using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Logging;
using System;
using System.Globalization;
using System.IO;
using System.Linq;
using MediaBrowser.Model.Logging;
using System.Threading;
using System.Threading.Tasks;
namespace MediaBrowser.Controller.Providers
{
@ -16,7 +15,8 @@ namespace MediaBrowser.Controller.Providers
/// </summary>
public class ImagesByNameProvider : ImageFromMediaLocationProvider
{
public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager) : base(logManager, configurationManager)
public ImagesByNameProvider(ILogManager logManager, IServerConfigurationManager configurationManager)
: base(logManager, configurationManager)
{
}
@ -88,14 +88,61 @@ namespace MediaBrowser.Controller.Providers
return DateTime.MinValue;
}
var files = FileSystem.GetFiles(location).ToList();
var files = new DirectoryInfo(location).EnumerateFiles("*", SearchOption.TopDirectoryOnly).ToList();
if (files.Count == 0)
{
return DateTime.MinValue;
}
return files.Select(f => f.CreationTimeUtc > f.LastWriteTimeUtc ? f.CreationTimeUtc : f.LastWriteTimeUtc).Max();
return files.Select(f =>
{
var lastWriteTime = GetLastWriteTimeUtc(f);
var creationTime = GetCreationTimeUtc(f);
return creationTime > lastWriteTime ? creationTime : lastWriteTime;
}).Max();
}
/// <summary>
/// Gets the creation time UTC.
/// </summary>
/// <param name="info">The info.</param>
/// <returns>DateTime.</returns>
private DateTime GetLastWriteTimeUtc(FileSystemInfo info)
{
// This could throw an error on some file systems that have dates out of range
try
{
return info.LastAccessTimeUtc;
}
catch (Exception ex)
{
Logger.ErrorException("Error determining LastAccessTimeUtc for {0}", ex, info.FullName);
return DateTime.MinValue;
}
}
/// <summary>
/// Gets the creation time UTC.
/// </summary>
/// <param name="info">The info.</param>
/// <returns>DateTime.</returns>
private DateTime GetCreationTimeUtc(FileSystemInfo info)
{
// This could throw an error on some file systems that have dates out of range
try
{
return info.CreationTimeUtc;
}
catch (Exception ex)
{
Logger.ErrorException("Error determining CreationTimeUtc for {0}", ex, info.FullName);
return DateTime.MinValue;
}
}
/// <summary>

View File

@ -1,9 +1,8 @@
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Library;
using MediaBrowser.Controller.Resolvers;
using System;
using System.IO;
using System.Linq;
using MediaBrowser.Controller.Resolvers;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
{
@ -32,7 +31,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
if (!args.IsDirectory)
{
if (IsAudioFile(args))
if (IsAudioFile(args.Path))
{
return new Controller.Entities.Audio.Audio();
}
@ -61,21 +60,11 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
/// <summary>
/// Determines whether [is audio file] [the specified args].
/// </summary>
/// <param name="args">The args.</param>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is audio file] [the specified args]; otherwise, <c>false</c>.</returns>
public static bool IsAudioFile(ItemResolveArgs args)
public static bool IsAudioFile(string path)
{
return AudioFileExtensions.Contains(Path.GetExtension(args.Path), StringComparer.OrdinalIgnoreCase);
}
/// <summary>
/// Determines whether [is audio file] [the specified file].
/// </summary>
/// <param name="file">The file.</param>
/// <returns><c>true</c> if [is audio file] [the specified file]; otherwise, <c>false</c>.</returns>
public static bool IsAudioFile(WIN32_FIND_DATA file)
{
return AudioFileExtensions.Contains(Path.GetExtension(file.Path), StringComparer.OrdinalIgnoreCase);
return AudioFileExtensions.Contains(Path.GetExtension(path), StringComparer.OrdinalIgnoreCase);
}
}
}

View File

@ -1,4 +1,6 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.IO;
using MediaBrowser.Controller.Library;
@ -40,15 +42,29 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
/// <summary>
/// Determine if the supplied file data points to a music album
/// </summary>
/// <param name="data">The data.</param>
/// <param name="path">The path.</param>
/// <returns><c>true</c> if [is music album] [the specified data]; otherwise, <c>false</c>.</returns>
public static bool IsMusicAlbum(WIN32_FIND_DATA data)
public static bool IsMusicAlbum(string path)
{
return ContainsMusic(FileSystem.GetFiles(data.Path));
// If list contains at least 2 audio files or at least one and no video files consider it to contain music
var foundAudio = 0;
foreach (var fullName in new DirectoryInfo(path).EnumerateFiles("*", SearchOption.TopDirectoryOnly).Select(file => file.FullName))
{
if (AudioResolver.IsAudioFile(fullName)) foundAudio++;
if (foundAudio >= 2)
{
return true;
}
if (EntityResolutionHelper.IsVideoFile(fullName)) return false;
}
// or a single audio file and no video files
return foundAudio > 0;
}
/// <summary>
/// Determine if the supplied reslove args should be considered a music album
/// Determine if the supplied resolve args should be considered a music album
/// </summary>
/// <param name="args">The args.</param>
/// <returns><c>true</c> if [is music album] [the specified args]; otherwise, <c>false</c>.</returns>
@ -74,20 +90,19 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
{
// If list contains at least 2 audio files or at least one and no video files consider it to contain music
var foundAudio = 0;
var foundVideo = 0;
foreach (var file in list)
{
if (AudioResolver.IsAudioFile(file)) foundAudio++;
if (AudioResolver.IsAudioFile(file.Path)) foundAudio++;
if (foundAudio >= 2)
{
return true;
}
if (EntityResolutionHelper.IsVideoFile(file.Path)) foundVideo++;
if (EntityResolutionHelper.IsVideoFile(file.Path)) return false;
}
// or a single audio file and no video files
if (foundAudio > 0 && foundVideo == 0) return true;
return false;
return foundAudio > 0;
}
}
}

View File

@ -1,7 +1,7 @@
using MediaBrowser.Controller.Entities.Audio;
using MediaBrowser.Controller.Library;
using System.Linq;
using MediaBrowser.Controller.Resolvers;
using System.Linq;
namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
{
@ -33,7 +33,7 @@ namespace MediaBrowser.Server.Implementations.Library.Resolvers.Audio
if (args.Parent.IsRoot) return null;
// If we contain an album assume we are an artist folder
return args.FileSystemChildren.Any(MusicAlbumResolver.IsMusicAlbum) ? new MusicArtist() : null;
return args.FileSystemChildren.Any(i => MusicAlbumResolver.IsMusicAlbum(i.Path)) ? new MusicArtist() : null;
}
}