mirror of
https://github.com/jellyfin/jellyfin.git
synced 2026-06-04 06:48:35 +01:00
replace file system calls with IFileSystem when needed
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Common.Extensions;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Configuration;
|
||||
using MediaBrowser.Controller.Entities.TV;
|
||||
using MediaBrowser.Controller.IO;
|
||||
@@ -1737,7 +1738,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
if (locationType == LocationType.Remote ||
|
||||
locationType == LocationType.Virtual)
|
||||
{
|
||||
return File.GetLastWriteTimeUtc(imagePath);
|
||||
return FileSystem.GetLastWriteTimeUtc(imagePath);
|
||||
}
|
||||
|
||||
var metaFileEntry = ResolveArgs.GetMetaFileByPath(imagePath);
|
||||
@@ -1754,7 +1755,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
}
|
||||
|
||||
// See if we can avoid a file system lookup by looking for the file in ResolveArgs
|
||||
return metaFileEntry == null ? File.GetLastWriteTimeUtc(imagePath) : metaFileEntry.LastWriteTimeUtc;
|
||||
return metaFileEntry == null ? FileSystem.GetLastWriteTimeUtc(imagePath) : FileSystem.GetLastWriteTimeUtc(metaFileEntry);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ namespace MediaBrowser.Controller.Entities
|
||||
// Ensure it's been lazy loaded
|
||||
var config = Configuration;
|
||||
|
||||
return File.GetLastWriteTimeUtc(ConfigurationFilePath);
|
||||
return FileSystem.GetLastWriteTimeUtc(ConfigurationFilePath);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
|
||||
@@ -1,71 +0,0 @@
|
||||
using MediaBrowser.Model.Logging;
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MediaBrowser.Controller.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// Class FileSystem
|
||||
/// </summary>
|
||||
public static class FileSystem
|
||||
{
|
||||
/// <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 GetLastWriteTimeUtc(FileSystemInfo info, ILogger logger)
|
||||
{
|
||||
// This could throw an error on some file systems that have dates out of range
|
||||
|
||||
try
|
||||
{
|
||||
return info.LastWriteTimeUtc;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
logger.ErrorException("Error determining LastAccessTimeUtc for {0}", ex, info.FullName);
|
||||
return DateTime.MinValue;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Copies all.
|
||||
/// </summary>
|
||||
/// <param name="source">The source.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
/// <exception cref="System.ArgumentNullException">source</exception>
|
||||
/// <exception cref="System.ArgumentException">The source and target directories are the same</exception>
|
||||
public static void CopyAll(string source, string target)
|
||||
{
|
||||
if (string.IsNullOrEmpty(source))
|
||||
{
|
||||
throw new ArgumentNullException("source");
|
||||
}
|
||||
if (string.IsNullOrEmpty(target))
|
||||
{
|
||||
throw new ArgumentNullException("target");
|
||||
}
|
||||
|
||||
if (source.Equals(target, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
throw new ArgumentException("The source and target directories are the same");
|
||||
}
|
||||
|
||||
// Check if the target directory exists, if not, create it.
|
||||
Directory.CreateDirectory(target);
|
||||
|
||||
foreach (var file in Directory.EnumerateFiles(source))
|
||||
{
|
||||
File.Copy(file, Path.Combine(target, Path.GetFileName(file)), true);
|
||||
}
|
||||
|
||||
// Copy each subdirectory using recursion.
|
||||
foreach (var dir in Directory.EnumerateDirectories(source))
|
||||
{
|
||||
CopyAll(dir, Path.Combine(target, Path.GetFileName(dir)));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,53 +0,0 @@
|
||||
using System;
|
||||
using System.IO;
|
||||
|
||||
namespace MediaBrowser.Controller.IO
|
||||
{
|
||||
/// <summary>
|
||||
/// Interface IFileSystem
|
||||
/// </summary>
|
||||
public interface IFileSystem
|
||||
{
|
||||
/// <summary>
|
||||
/// Determines whether the specified filename is shortcut.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <returns><c>true</c> if the specified filename is shortcut; otherwise, <c>false</c>.</returns>
|
||||
bool IsShortcut(string filename);
|
||||
|
||||
/// <summary>
|
||||
/// Resolves the shortcut.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string ResolveShortcut(string filename);
|
||||
|
||||
/// <summary>
|
||||
/// Creates the shortcut.
|
||||
/// </summary>
|
||||
/// <param name="shortcutPath">The shortcut path.</param>
|
||||
/// <param name="target">The target.</param>
|
||||
void CreateShortcut(string shortcutPath, string target);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the file system info.
|
||||
/// </summary>
|
||||
/// <param name="path">The path.</param>
|
||||
/// <returns>FileSystemInfo.</returns>
|
||||
FileSystemInfo GetFileSystemInfo(string path);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the valid filename.
|
||||
/// </summary>
|
||||
/// <param name="filename">The filename.</param>
|
||||
/// <returns>System.String.</returns>
|
||||
string GetValidFilename(string filename);
|
||||
|
||||
/// <summary>
|
||||
/// Gets the creation time UTC.
|
||||
/// </summary>
|
||||
/// <param name="info">The info.</param>
|
||||
/// <returns>DateTime.</returns>
|
||||
DateTime GetCreationTimeUtc(FileSystemInfo info);
|
||||
}
|
||||
}
|
||||
@@ -94,7 +94,6 @@
|
||||
<Compile Include="Entities\ImageSourceInfo.cs" />
|
||||
<Compile Include="Entities\LinkedChild.cs" />
|
||||
<Compile Include="Entities\MusicVideo.cs" />
|
||||
<Compile Include="IO\IFileSystem.cs" />
|
||||
<Compile Include="Library\ILibraryPostScanTask.cs" />
|
||||
<Compile Include="Library\ILibraryPrescanTask.cs" />
|
||||
<Compile Include="Library\IMetadataSaver.cs" />
|
||||
@@ -141,7 +140,6 @@
|
||||
<Compile Include="Entities\Video.cs" />
|
||||
<Compile Include="Entities\CollectionFolder.cs" />
|
||||
<Compile Include="Entities\Year.cs" />
|
||||
<Compile Include="IO\FileSystem.cs" />
|
||||
<Compile Include="IO\IDirectoryWatchers.cs" />
|
||||
<Compile Include="IServerApplicationHost.cs" />
|
||||
<Compile Include="IServerApplicationPaths.cs" />
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Common.MediaInfo;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Persistence;
|
||||
using MediaBrowser.Model.Entities;
|
||||
using MediaBrowser.Model.Logging;
|
||||
@@ -35,6 +36,8 @@ namespace MediaBrowser.Controller.MediaInfo
|
||||
private readonly ILogger _logger;
|
||||
private readonly IItemRepository _itemRepo;
|
||||
|
||||
private readonly IFileSystem _fileSystem;
|
||||
|
||||
/// <summary>
|
||||
/// Initializes a new instance of the <see cref="FFMpegManager" /> class.
|
||||
/// </summary>
|
||||
@@ -43,12 +46,13 @@ namespace MediaBrowser.Controller.MediaInfo
|
||||
/// <param name="logger">The logger.</param>
|
||||
/// <param name="itemRepo">The item repo.</param>
|
||||
/// <exception cref="System.ArgumentNullException">zipClient</exception>
|
||||
public FFMpegManager(IServerApplicationPaths appPaths, IMediaEncoder encoder, ILogger logger, IItemRepository itemRepo)
|
||||
public FFMpegManager(IServerApplicationPaths appPaths, IMediaEncoder encoder, ILogger logger, IItemRepository itemRepo, IFileSystem fileSystem)
|
||||
{
|
||||
_appPaths = appPaths;
|
||||
_encoder = encoder;
|
||||
_logger = logger;
|
||||
_itemRepo = itemRepo;
|
||||
_fileSystem = fileSystem;
|
||||
|
||||
VideoImageCache = new FileSystemRepository(VideoImagesDataPath);
|
||||
SubtitleCache = new FileSystemRepository(SubtitleCachePath);
|
||||
@@ -203,7 +207,7 @@ namespace MediaBrowser.Controller.MediaInfo
|
||||
|
||||
if (stream.IsExternal)
|
||||
{
|
||||
ticksParam += File.GetLastWriteTimeUtc(stream.Path).Ticks;
|
||||
ticksParam += _fileSystem.GetLastWriteTimeUtc(stream.Path).Ticks;
|
||||
}
|
||||
|
||||
return SubtitleCache.GetResourcePath(input.Id + "_" + subtitleStreamIndex + "_" + input.DateModified.Ticks + ticksParam, outputExtension);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Common.IO;
|
||||
using MediaBrowser.Controller.Entities;
|
||||
using MediaBrowser.Controller.IO;
|
||||
using MediaBrowser.Controller.Library;
|
||||
using System;
|
||||
@@ -149,7 +150,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||
item.DateCreated = fileSystem.GetCreationTimeUtc(childData);
|
||||
}
|
||||
|
||||
item.DateModified = childData.LastWriteTimeUtc;
|
||||
item.DateModified = fileSystem.GetLastWriteTimeUtc(childData);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -161,7 +162,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||
{
|
||||
item.DateCreated = fileSystem.GetCreationTimeUtc(fileData);
|
||||
}
|
||||
item.DateModified = fileData.LastWriteTimeUtc;
|
||||
item.DateModified = fileSystem.GetLastWriteTimeUtc(fileData);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -171,7 +172,7 @@ namespace MediaBrowser.Controller.Resolvers
|
||||
{
|
||||
item.DateCreated = fileSystem.GetCreationTimeUtc(args.FileInfo);
|
||||
}
|
||||
item.DateModified = args.FileInfo.LastWriteTimeUtc;
|
||||
item.DateModified = fileSystem.GetLastWriteTimeUtc(args.FileInfo);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user