aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Controller
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-27 20:44:38 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2013-04-27 20:44:38 -0400
commit90bb3d46c416676105d5cf89d12279b3f7ccb944 (patch)
tree513abf9caa18fa206ec8b7a582bdf9fe4ae24425 /MediaBrowser.Controller
parente7443027090fd874f2c9a733eaf23bc43d6dd291 (diff)
#200 - MB3 Locking Folders for a long time
Diffstat (limited to 'MediaBrowser.Controller')
-rw-r--r--MediaBrowser.Controller/IO/FileSystem.cs10
-rw-r--r--MediaBrowser.Controller/Providers/ImagesByNameProvider.cs63
2 files changed, 55 insertions, 18 deletions
diff --git a/MediaBrowser.Controller/IO/FileSystem.cs b/MediaBrowser.Controller/IO/FileSystem.cs
index 28deca1009..7b031744e7 100644
--- a/MediaBrowser.Controller/IO/FileSystem.cs
+++ b/MediaBrowser.Controller/IO/FileSystem.cs
@@ -79,16 +79,6 @@ namespace MediaBrowser.Controller.IO
}
/// <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>
/// <param name="path">The path.</param>
diff --git a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs
index 7b7be660d6..26ef984637 100644
--- a/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs
+++ b/MediaBrowser.Controller/Providers/ImagesByNameProvider.cs
@@ -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>