diff options
Diffstat (limited to 'Emby.Common.Implementations')
5 files changed, 69 insertions, 23 deletions
diff --git a/Emby.Common.Implementations/Devices/DeviceId.cs b/Emby.Common.Implementations/Devices/DeviceId.cs index 3d23ab872..1de76456c 100644 --- a/Emby.Common.Implementations/Devices/DeviceId.cs +++ b/Emby.Common.Implementations/Devices/DeviceId.cs @@ -57,7 +57,7 @@ namespace Emby.Common.Implementations.Devices { var path = CachePath; - _fileSystem.CreateDirectory(Path.GetDirectoryName(path)); + _fileSystem.CreateDirectory(_fileSystem.GetDirectoryName(path)); lock (_syncLock) { diff --git a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs index 23f33f06c..eb9bc1bd0 100644 --- a/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs +++ b/Emby.Common.Implementations/HttpClientManager/HttpClientManager.cs @@ -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) { diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index ba73c1ba2..3ed4f650f 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -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); diff --git a/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs b/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs index c1e429dc9..0a407d64f 100644 --- a/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs +++ b/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs @@ -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) diff --git a/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs b/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs index f0518f69e..ac1c55b6b 100644 --- a/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs +++ b/Emby.Common.Implementations/ScheduledTasks/ScheduledTaskWorker.cs @@ -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); } |
