aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/IO/ManagedFileSystem.cs
diff options
context:
space:
mode:
Diffstat (limited to 'Emby.Server.Implementations/IO/ManagedFileSystem.cs')
-rw-r--r--Emby.Server.Implementations/IO/ManagedFileSystem.cs46
1 files changed, 16 insertions, 30 deletions
diff --git a/Emby.Server.Implementations/IO/ManagedFileSystem.cs b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
index bee96c785..3e7774abf 100644
--- a/Emby.Server.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
@@ -5,8 +5,8 @@ using System.IO;
using System.Linq;
using System.Text;
using MediaBrowser.Model.IO;
-using Microsoft.Extensions.Logging;
using MediaBrowser.Model.System;
+using Microsoft.Extensions.Logging;
namespace Emby.Server.Implementations.IO
{
@@ -29,9 +29,14 @@ namespace Emby.Server.Implementations.IO
private string _defaultDirectory;
- public ManagedFileSystem(ILogger logger, IEnvironmentInfo environmentInfo, string defaultDirectory, string tempPath, bool enableSeparateFileAndDirectoryQueries)
+ public ManagedFileSystem(
+ ILoggerFactory loggerFactory,
+ IEnvironmentInfo environmentInfo,
+ string defaultDirectory,
+ string tempPath,
+ bool enableSeparateFileAndDirectoryQueries)
{
- Logger = logger;
+ Logger = loggerFactory.CreateLogger("FileSystem");
_supportsAsyncFileStreams = true;
_tempPath = tempPath;
_environmentInfo = environmentInfo;
@@ -101,7 +106,7 @@ namespace Emby.Server.Implementations.IO
/// </summary>
/// <param name="filename">The filename.</param>
/// <returns><c>true</c> if the specified filename is shortcut; otherwise, <c>false</c>.</returns>
- /// <exception cref="System.ArgumentNullException">filename</exception>
+ /// <exception cref="ArgumentNullException">filename</exception>
public virtual bool IsShortcut(string filename)
{
if (string.IsNullOrEmpty(filename))
@@ -118,7 +123,7 @@ namespace Emby.Server.Implementations.IO
/// </summary>
/// <param name="filename">The filename.</param>
/// <returns>System.String.</returns>
- /// <exception cref="System.ArgumentNullException">filename</exception>
+ /// <exception cref="ArgumentNullException">filename</exception>
public virtual string ResolveShortcut(string filename)
{
if (string.IsNullOrEmpty(filename))
@@ -185,7 +190,7 @@ namespace Emby.Server.Implementations.IO
/// </summary>
/// <param name="shortcutPath">The shortcut path.</param>
/// <param name="target">The target.</param>
- /// <exception cref="System.ArgumentNullException">
+ /// <exception cref="ArgumentNullException">
/// shortcutPath
/// or
/// target
@@ -344,7 +349,7 @@ namespace Emby.Server.Implementations.IO
/// </summary>
/// <param name="filename">The filename.</param>
/// <returns>System.String.</returns>
- /// <exception cref="System.ArgumentNullException">filename</exception>
+ /// <exception cref="ArgumentNullException">filename</exception>
public string GetValidFilename(string filename)
{
var builder = new StringBuilder(filename);
@@ -445,10 +450,7 @@ namespace Emby.Server.Implementations.IO
}
public Stream GetFileStream(string path, FileOpenMode mode, FileAccessMode access, FileShareMode share, FileOpenOptions fileOpenOptions)
- {
- var defaultBufferSize = 4096;
- return new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), defaultBufferSize, GetFileOptions(fileOpenOptions));
- }
+ => new FileStream(path, GetFileMode(mode), GetFileAccess(access), GetFileShare(share), 4096, GetFileOptions(fileOpenOptions));
private static FileOptions GetFileOptions(FileOpenOptions mode)
{
@@ -526,7 +528,7 @@ namespace Emby.Server.Implementations.IO
}
else
{
- FileAttributes attributes = File.GetAttributes(path);
+ var attributes = File.GetAttributes(path);
attributes = RemoveAttribute(attributes, FileAttributes.Hidden);
File.SetAttributes(path, attributes);
}
@@ -550,7 +552,7 @@ namespace Emby.Server.Implementations.IO
}
else
{
- FileAttributes attributes = File.GetAttributes(path);
+ var attributes = File.GetAttributes(path);
attributes = RemoveAttribute(attributes, FileAttributes.ReadOnly);
File.SetAttributes(path, attributes);
}
@@ -759,18 +761,13 @@ namespace Emby.Server.Implementations.IO
// Only include drives in the ready state or this method could end up being very slow, waiting for drives to timeout
return DriveInfo.GetDrives().Where(d => d.IsReady).Select(d => new FileSystemMetadata
{
- Name = GetName(d),
+ Name = d.Name,
FullName = d.RootDirectory.FullName,
IsDirectory = true
}).ToList();
}
- private static string GetName(DriveInfo drive)
- {
- return drive.Name;
- }
-
public IEnumerable<FileSystemMetadata> GetDirectories(string path, bool recursive = false)
{
var searchOption = recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly;
@@ -846,17 +843,6 @@ namespace Emby.Server.Implementations.IO
return File.OpenRead(path);
}
- private void CopyFileUsingStreams(string source, string target, bool overwrite)
- {
- using (var sourceStream = OpenRead(source))
- {
- using (var targetStream = GetFileStream(target, FileOpenMode.Create, FileAccessMode.Write, FileShareMode.Read))
- {
- sourceStream.CopyTo(targetStream);
- }
- }
- }
-
public void CopyFile(string source, string target, bool overwrite)
{
File.Copy(source, target, overwrite);