use IFileSystem interface to get creation time

This commit is contained in:
Luke Pulverenti 2013-10-30 19:15:58 -04:00
parent d5baaa1f67
commit 579b507f7f
9 changed files with 52 additions and 31 deletions

View File

@ -30,27 +30,6 @@ namespace MediaBrowser.Controller.IO
} }
} }
/// <summary>
/// Gets the creation time UTC.
/// </summary>
/// <param name="info">The info.</param>
/// <param name="logger">The logger.</param>
/// <returns>DateTime.</returns>
public static DateTime GetCreationTimeUtc(FileSystemInfo info, ILogger logger)
{
// 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> /// <summary>
/// Copies all. /// Copies all.
/// </summary> /// </summary>

View File

@ -1,4 +1,5 @@
using System.IO; using System;
using System.IO;
namespace MediaBrowser.Controller.IO namespace MediaBrowser.Controller.IO
{ {
@ -41,5 +42,12 @@ namespace MediaBrowser.Controller.IO
/// <param name="filename">The filename.</param> /// <param name="filename">The filename.</param>
/// <returns>System.String.</returns> /// <returns>System.String.</returns>
string GetValidFilename(string filename); string GetValidFilename(string filename);
/// <summary>
/// Gets the creation time UTC.
/// </summary>
/// <param name="info">The info.</param>
/// <returns>DateTime.</returns>
DateTime GetCreationTimeUtc(FileSystemInfo info);
} }
} }

View File

@ -146,7 +146,7 @@ namespace MediaBrowser.Controller.Resolvers
{ {
if (includeCreationTime) if (includeCreationTime)
{ {
item.DateCreated = childData.CreationTimeUtc; item.DateCreated = fileSystem.GetCreationTimeUtc(childData);
} }
item.DateModified = childData.LastWriteTimeUtc; item.DateModified = childData.LastWriteTimeUtc;
@ -159,7 +159,7 @@ namespace MediaBrowser.Controller.Resolvers
{ {
if (includeCreationTime) if (includeCreationTime)
{ {
item.DateCreated = fileData.CreationTimeUtc; item.DateCreated = fileSystem.GetCreationTimeUtc(fileData);
} }
item.DateModified = fileData.LastWriteTimeUtc; item.DateModified = fileData.LastWriteTimeUtc;
} }
@ -169,7 +169,7 @@ namespace MediaBrowser.Controller.Resolvers
{ {
if (includeCreationTime) if (includeCreationTime)
{ {
item.DateCreated = args.FileInfo.CreationTimeUtc; item.DateCreated = fileSystem.GetCreationTimeUtc(args.FileInfo);
} }
item.DateModified = args.FileInfo.LastWriteTimeUtc; item.DateModified = args.FileInfo.LastWriteTimeUtc;
} }

View File

@ -114,7 +114,7 @@ namespace MediaBrowser.Providers
return files.Select(f => return files.Select(f =>
{ {
var lastWriteTime = FileSystem.GetLastWriteTimeUtc(f, Logger); var lastWriteTime = FileSystem.GetLastWriteTimeUtc(f, Logger);
var creationTime = FileSystem.GetCreationTimeUtc(f, Logger); var creationTime = _fileSystem.GetCreationTimeUtc(f);
return creationTime > lastWriteTime ? creationTime : lastWriteTime; return creationTime > lastWriteTime ? creationTime : lastWriteTime;

View File

@ -771,7 +771,7 @@ namespace MediaBrowser.Server.Implementations.Library
{ {
Name = name, Name = name,
Id = id, Id = id,
DateCreated = fileInfo.CreationTimeUtc, DateCreated = _fileSystem.GetCreationTimeUtc(fileInfo),
DateModified = fileInfo.LastWriteTimeUtc, DateModified = fileInfo.LastWriteTimeUtc,
Path = path Path = path
}; };

View File

@ -249,7 +249,7 @@ namespace MediaBrowser.ServerApplication
RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer()); RegisterSingleInstance<IBlurayExaminer>(() => new BdInfoExaminer());
FileSystemManager = FileSystemFactory.CreateFileSystemManager(); FileSystemManager = FileSystemFactory.CreateFileSystemManager(LogManager);
RegisterSingleInstance(FileSystemManager); RegisterSingleInstance(FileSystemManager);
var mediaEncoderTask = RegisterMediaEncoder(); var mediaEncoderTask = RegisterMediaEncoder();

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.IO; using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Logging;
using System; using System;
using System.IO; using System.IO;
using System.Text; using System.Text;
@ -10,6 +11,13 @@ namespace MediaBrowser.ServerApplication.IO
/// </summary> /// </summary>
public class CommonFileSystem : IFileSystem public class CommonFileSystem : IFileSystem
{ {
protected ILogger Logger;
public CommonFileSystem(ILogger logger)
{
Logger = logger;
}
/// <summary> /// <summary>
/// Determines whether the specified filename is shortcut. /// Determines whether the specified filename is shortcut.
/// </summary> /// </summary>
@ -137,6 +145,25 @@ namespace MediaBrowser.ServerApplication.IO
return builder.ToString(); return builder.ToString();
} }
/// <summary>
/// Gets the creation time UTC.
/// </summary>
/// <param name="info">The info.</param>
/// <returns>DateTime.</returns>
public 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;
}
}
} }

View File

@ -1,4 +1,5 @@
using MediaBrowser.Controller.IO; using MediaBrowser.Controller.IO;
using MediaBrowser.Model.Logging;
namespace MediaBrowser.ServerApplication.IO namespace MediaBrowser.ServerApplication.IO
{ {
@ -11,9 +12,9 @@ namespace MediaBrowser.ServerApplication.IO
/// Creates the file system manager. /// Creates the file system manager.
/// </summary> /// </summary>
/// <returns>IFileSystem.</returns> /// <returns>IFileSystem.</returns>
public static IFileSystem CreateFileSystemManager() public static IFileSystem CreateFileSystemManager(ILogManager logManager)
{ {
return new NativeFileSystem(); return new NativeFileSystem(logManager.GetLogger("FileSystem"));
} }
} }
} }

View File

@ -1,4 +1,5 @@
using System; using MediaBrowser.Model.Logging;
using System;
using System.IO; using System.IO;
using System.Runtime.InteropServices; using System.Runtime.InteropServices;
using System.Security; using System.Security;
@ -8,6 +9,11 @@ namespace MediaBrowser.ServerApplication.IO
{ {
public class NativeFileSystem : CommonFileSystem public class NativeFileSystem : CommonFileSystem
{ {
public NativeFileSystem(ILogger logger)
: base(logger)
{
}
public override bool IsShortcut(string filename) public override bool IsShortcut(string filename)
{ {
return base.IsShortcut(filename) || return base.IsShortcut(filename) ||