improve smb support

This commit is contained in:
Luke Pulverenti
2017-05-04 14:14:45 -04:00
parent 53024bd149
commit 696a6b34ea
80 changed files with 256 additions and 151 deletions

View File

@@ -57,7 +57,7 @@ namespace Emby.Common.Implementations.Devices
{
var path = CachePath;
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
lock (_syncLock)
{

View File

@@ -418,7 +418,7 @@ namespace Emby.Common.Implementations.HttpClientManager
private async Task CacheResponse(HttpResponseInfo response, string responseCachePath)
{
_fileSystem.CreateDirectory(Path.GetDirectoryName(responseCachePath));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(responseCachePath));
using (var responseStream = response.Content)
{

View File

@@ -546,24 +546,6 @@ namespace Emby.Common.Implementations.IO
return Path.DirectorySeparatorChar;
}
public bool AreEqual(string path1, string path2)
{
if (path1 == null && path2 == null)
{
return true;
}
if (path1 == null || path2 == null)
{
return false;
}
path1 = path1.TrimEnd(GetDirectorySeparatorChar(path1));
path2 = path2.TrimEnd(GetDirectorySeparatorChar(path2));
return string.Equals(path1, path2, StringComparison.OrdinalIgnoreCase);
}
public bool ContainsSubPath(string parentPath, string path)
{
if (string.IsNullOrEmpty(parentPath))
@@ -588,7 +570,7 @@ namespace Emby.Common.Implementations.IO
throw new ArgumentNullException("path");
}
var parent = Path.GetDirectoryName(path);
var parent = GetDirectoryName(path);
if (!string.IsNullOrEmpty(parent))
{
@@ -598,6 +580,16 @@ namespace Emby.Common.Implementations.IO
return true;
}
public string GetDirectoryName(string path)
{
if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
return _sharpCifsFileSystem.GetDirectoryName(path);
}
return Path.GetDirectoryName(path);
}
public string NormalizePath(string path)
{
if (string.IsNullOrEmpty(path))
@@ -605,6 +597,11 @@ namespace Emby.Common.Implementations.IO
throw new ArgumentNullException("path");
}
if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
return _sharpCifsFileSystem.NormalizePath(path);
}
if (path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
{
return path;
@@ -613,6 +610,21 @@ namespace Emby.Common.Implementations.IO
return path.TrimEnd(GetDirectorySeparatorChar(path));
}
public bool AreEqual(string path1, string path2)
{
if (path1 == null && path2 == null)
{
return true;
}
if (path1 == null || path2 == null)
{
return false;
}
return string.Equals(NormalizePath(path1), NormalizePath(path2), StringComparison.OrdinalIgnoreCase);
}
public string GetFileNameWithoutExtension(FileSystemMetadata info)
{
if (info.IsDirectory)
@@ -637,11 +649,17 @@ namespace Emby.Common.Implementations.IO
// Cannot use Path.IsPathRooted because it returns false under mono when using windows-based paths, e.g. C:\\
if (_sharpCifsFileSystem.IsEnabledForPath(path))
{
return true;
}
if (path.IndexOf("://", StringComparison.OrdinalIgnoreCase) != -1 &&
!path.StartsWith("file://", StringComparison.OrdinalIgnoreCase))
{
return false;
}
return true;
//return Path.IsPathRooted(path);

View File

@@ -30,6 +30,34 @@ namespace Emby.Common.Implementations.IO
return path.StartsWith("smb://", StringComparison.OrdinalIgnoreCase) || IsUncPath(path);
}
public string NormalizePath(string path)
{
if (path.StartsWith("smb://", StringComparison.OrdinalIgnoreCase))
{
return path;
}
if (IsUncPath(path))
{
return ConvertUncToSmb(path);
}
return path;
}
public string GetDirectoryName(string path)
{
var separator = GetDirectorySeparatorChar(path);
var result = Path.GetDirectoryName(path);
if (separator == '/')
{
result = result.Replace('\\', '/');
}
return result;
}
public char GetDirectorySeparatorChar(string path)
{
if (path.IndexOf('/') != -1)

View File

@@ -158,7 +158,7 @@ namespace Emby.Common.Implementations.ScheduledTasks
_lastExecutionResult = value;
var path = GetHistoryFilePath();
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
lock (_lastExecutionResultSyncLock)
{
@@ -575,7 +575,7 @@ namespace Emby.Common.Implementations.ScheduledTasks
{
var path = GetConfigurationFilePath();
_fileSystem.CreateDirectory(Path.GetDirectoryName(path));
_fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path));
JsonSerializer.SerializeToFile(triggers, path);
}