|
|
@ -4,8 +4,10 @@ using System.Diagnostics;
|
|
|
|
using System.IO;
|
|
|
|
using System.IO;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Linq;
|
|
|
|
using System.Text;
|
|
|
|
using System.Text;
|
|
|
|
|
|
|
|
using MediaBrowser.Common.Configuration;
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
using MediaBrowser.Model.IO;
|
|
|
|
using MediaBrowser.Model.System;
|
|
|
|
using MediaBrowser.Model.System;
|
|
|
|
|
|
|
|
using Microsoft.Extensions.Configuration;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Emby.Server.Implementations.IO
|
|
|
|
namespace Emby.Server.Implementations.IO
|
|
|
@ -20,61 +22,27 @@ namespace Emby.Server.Implementations.IO
|
|
|
|
private readonly bool _supportsAsyncFileStreams;
|
|
|
|
private readonly bool _supportsAsyncFileStreams;
|
|
|
|
private char[] _invalidFileNameChars;
|
|
|
|
private char[] _invalidFileNameChars;
|
|
|
|
private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
|
|
|
|
private readonly List<IShortcutHandler> _shortcutHandlers = new List<IShortcutHandler>();
|
|
|
|
private bool EnableSeparateFileAndDirectoryQueries;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private string _tempPath;
|
|
|
|
private readonly string _tempPath;
|
|
|
|
|
|
|
|
|
|
|
|
private IEnvironmentInfo _environmentInfo;
|
|
|
|
private readonly IEnvironmentInfo _environmentInfo;
|
|
|
|
private bool _isEnvironmentCaseInsensitive;
|
|
|
|
private readonly bool _isEnvironmentCaseInsensitive;
|
|
|
|
|
|
|
|
|
|
|
|
private string _defaultDirectory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public ManagedFileSystem(
|
|
|
|
public ManagedFileSystem(
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
ILoggerFactory loggerFactory,
|
|
|
|
IEnvironmentInfo environmentInfo,
|
|
|
|
IEnvironmentInfo environmentInfo,
|
|
|
|
string defaultDirectory,
|
|
|
|
IApplicationPaths applicationPaths)
|
|
|
|
string tempPath,
|
|
|
|
|
|
|
|
bool enableSeparateFileAndDirectoryQueries)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
Logger = loggerFactory.CreateLogger("FileSystem");
|
|
|
|
Logger = loggerFactory.CreateLogger("FileSystem");
|
|
|
|
_supportsAsyncFileStreams = true;
|
|
|
|
_supportsAsyncFileStreams = true;
|
|
|
|
_tempPath = tempPath;
|
|
|
|
_tempPath = applicationPaths.TempDirectory;
|
|
|
|
_environmentInfo = environmentInfo;
|
|
|
|
_environmentInfo = environmentInfo;
|
|
|
|
_defaultDirectory = defaultDirectory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// On Linux with mono, this needs to be true or symbolic links are ignored
|
|
|
|
|
|
|
|
EnableSeparateFileAndDirectoryQueries = enableSeparateFileAndDirectoryQueries;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
SetInvalidFileNameChars(environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows);
|
|
|
|
SetInvalidFileNameChars(environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows);
|
|
|
|
|
|
|
|
|
|
|
|
_isEnvironmentCaseInsensitive = environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows;
|
|
|
|
_isEnvironmentCaseInsensitive = environmentInfo.OperatingSystem == MediaBrowser.Model.System.OperatingSystem.Windows;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual string DefaultDirectory
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
get
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
var value = _defaultDirectory;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!string.IsNullOrEmpty(value))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
try
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (Directory.Exists(value))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
return value;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
catch
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public virtual void AddShortcutHandler(IShortcutHandler handler)
|
|
|
|
public virtual void AddShortcutHandler(IShortcutHandler handler)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
_shortcutHandlers.Add(handler);
|
|
|
|
_shortcutHandlers.Add(handler);
|
|
|
@ -718,7 +686,7 @@ namespace Emby.Server.Implementations.IO
|
|
|
|
SetAttributes(path, false, false);
|
|
|
|
SetAttributes(path, false, false);
|
|
|
|
File.Delete(path);
|
|
|
|
File.Delete(path);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual List<FileSystemMetadata> GetDrives()
|
|
|
|
public virtual List<FileSystemMetadata> GetDrives()
|
|
|
|
{
|
|
|
|
{
|
|
|
|
// Only include drives in the ready state or this method could end up being very slow, waiting for drives to timeout
|
|
|
|
// Only include drives in the ready state or this method could end up being very slow, waiting for drives to timeout
|
|
|
@ -777,20 +745,15 @@ namespace Emby.Server.Implementations.IO
|
|
|
|
var directoryInfo = new DirectoryInfo(path);
|
|
|
|
var directoryInfo = new DirectoryInfo(path);
|
|
|
|
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
|
|
|
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
|
|
|
|
|
|
|
|
|
|
|
if (EnableSeparateFileAndDirectoryQueries)
|
|
|
|
return ToMetadata(directoryInfo.EnumerateDirectories("*", searchOption))
|
|
|
|
{
|
|
|
|
.Concat(ToMetadata(directoryInfo.EnumerateFiles("*", searchOption)));
|
|
|
|
return ToMetadata(directoryInfo.EnumerateDirectories("*", searchOption))
|
|
|
|
|
|
|
|
.Concat(ToMetadata(directoryInfo.EnumerateFiles("*", searchOption)));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return ToMetadata(directoryInfo.EnumerateFileSystemInfos("*", searchOption));
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private IEnumerable<FileSystemMetadata> ToMetadata(IEnumerable<FileSystemInfo> infos)
|
|
|
|
private IEnumerable<FileSystemMetadata> ToMetadata(IEnumerable<FileSystemInfo> infos)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return infos.Select(GetFileSystemMetadata);
|
|
|
|
return infos.Select(GetFileSystemMetadata);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public virtual IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false)
|
|
|
|
public virtual IEnumerable<string> GetDirectoryPaths(string path, bool recursive = false)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
|
|
|
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
|
|
|
|