From 733b891f529c2458d65560f556edf68052be2846 Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sat, 1 Apr 2017 20:36:06 -0400 Subject: stub out cifs support --- MediaBrowser.Model/IO/IFileSystem.cs | 25 ++----------------------- 1 file changed, 2 insertions(+), 23 deletions(-) (limited to 'MediaBrowser.Model/IO/IFileSystem.cs') diff --git a/MediaBrowser.Model/IO/IFileSystem.cs b/MediaBrowser.Model/IO/IFileSystem.cs index e791503ab..59e31debd 100644 --- a/MediaBrowser.Model/IO/IFileSystem.cs +++ b/MediaBrowser.Model/IO/IFileSystem.cs @@ -353,24 +353,7 @@ namespace MediaBrowser.Model.IO // permission is required. If the file is opened with FileAccess.ReadWrite, both // System.Security.Permissions.FileIOPermissionAccess.Read and System.Security.Permissions.FileIOPermissionAccess.Write // permissions are required. - OpenOrCreate = 4, - // - // Summary: - // Specifies that the operating system should open an existing file. When the file - // is opened, it should be truncated so that its size is zero bytes. This requires - // System.Security.Permissions.FileIOPermissionAccess.Write permission. Attempts - // to read from a file opened with FileMode.Truncate cause an System.ArgumentException - // exception. - Truncate = 5, - // - // Summary: - // Opens the file if it exists and seeks to the end of the file, or creates a new - // file. This requires System.Security.Permissions.FileIOPermissionAccess.Append - // permission. FileMode.Append can be used only in conjunction with FileAccess.Write. - // Trying to seek to a position before the end of the file throws an System.IO.IOException - // exception, and any attempt to read fails and throws a System.NotSupportedException - // exception. - Append = 6 + OpenOrCreate = 4 } public enum FileAccessMode @@ -384,11 +367,7 @@ namespace MediaBrowser.Model.IO // Summary: // Write access to the file. Data can be written to the file. Combine with Read // for read/write access. - Write = 2, - // - // Summary: - // Read and write access to the file. Data can be written to and read from the file. - ReadWrite = 3 + Write = 2 } public enum FileShareMode -- cgit v1.2.3 From 6e4d2342120c4bde4fdc99bc17dea0aec7b75ced Mon Sep 17 00:00:00 2001 From: Luke Pulverenti Date: Sun, 2 Apr 2017 00:08:07 -0400 Subject: update directory picker --- .../IO/ManagedFileSystem.cs | 28 ++++++++++++---------- .../IO/SharpCifsFileSystem.cs | 21 ++++++++++------ .../HttpServer/HttpListenerHost.cs | 13 ++++++++-- MediaBrowser.Model/IO/IFileSystem.cs | 1 - 4 files changed, 41 insertions(+), 22 deletions(-) (limited to 'MediaBrowser.Model/IO/IFileSystem.cs') diff --git a/Emby.Common.Implementations/IO/ManagedFileSystem.cs b/Emby.Common.Implementations/IO/ManagedFileSystem.cs index f1f044bc5..d1903851f 100644 --- a/Emby.Common.Implementations/IO/ManagedFileSystem.cs +++ b/Emby.Common.Implementations/IO/ManagedFileSystem.cs @@ -69,14 +69,6 @@ namespace Emby.Common.Implementations.IO } } - public char PathSeparator - { - get - { - return Path.PathSeparator; - } - } - public string GetFullPath(string path) { return Path.GetFullPath(path); @@ -544,6 +536,16 @@ namespace Emby.Common.Implementations.IO CopyFile(temp1, file2, true); } + private char GetSeparatorChar(string path) + { + if (path.IndexOf('/') != -1) + { + return '/'; + } + + return '\\'; + } + public bool AreEqual(string path1, string path2) { if (path1 == null && path2 == null) @@ -556,8 +558,8 @@ namespace Emby.Common.Implementations.IO return false; } - path1 = path1.TrimEnd(DirectorySeparatorChar); - path2 = path2.TrimEnd(DirectorySeparatorChar); + path1 = path1.TrimEnd(GetSeparatorChar(path1)); + path2 = path2.TrimEnd(GetSeparatorChar(path2)); return string.Equals(path1, path2, StringComparison.OrdinalIgnoreCase); } @@ -574,7 +576,9 @@ namespace Emby.Common.Implementations.IO throw new ArgumentNullException("path"); } - return path.IndexOf(parentPath.TrimEnd(Path.DirectorySeparatorChar) + Path.DirectorySeparatorChar, StringComparison.OrdinalIgnoreCase) != -1; + var separatorChar = GetSeparatorChar(parentPath); + + return path.IndexOf(parentPath.TrimEnd(separatorChar) + separatorChar, StringComparison.OrdinalIgnoreCase) != -1; } public bool IsRootPath(string path) @@ -606,7 +610,7 @@ namespace Emby.Common.Implementations.IO return path; } - return path.TrimEnd(Path.DirectorySeparatorChar); + return path.TrimEnd(GetSeparatorChar(path)); } public string GetFileNameWithoutExtension(FileSystemMetadata info) diff --git a/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs b/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs index fb32669f1..f2157b7af 100644 --- a/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs +++ b/Emby.Common.Implementations/IO/SharpCifsFileSystem.cs @@ -55,7 +55,7 @@ namespace Emby.Common.Implementations.IO private string GetReturnPath(SmbFile file) { - return file.GetCanonicalPath(); + return file.GetCanonicalPath().TrimEnd('/'); //return file.GetPath(); } @@ -419,9 +419,16 @@ namespace Emby.Common.Implementations.IO } } + private SmbFile CreateSmbDirectoryForListFiles(string path) + { + // In order to call ListFiles, it has to end with the separator + + return CreateSmbFile(path.TrimEnd('/') + '/'); + } + public IEnumerable GetDirectories(string path, bool recursive = false) { - var dir = CreateSmbFile(path); + var dir = CreateSmbDirectoryForListFiles(path); AssertDirectoryExists(dir, path); var list = ListFiles(dir, recursive); @@ -437,7 +444,7 @@ namespace Emby.Common.Implementations.IO public IEnumerable GetFiles(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false) { - var dir = CreateSmbFile(path); + var dir = CreateSmbDirectoryForListFiles(path); AssertDirectoryExists(dir, path); var list = ListFiles(dir, recursive); @@ -459,7 +466,7 @@ namespace Emby.Common.Implementations.IO public IEnumerable GetFileSystemEntries(string path, bool recursive = false) { - var dir = CreateSmbFile(path); + var dir = CreateSmbDirectoryForListFiles(path); AssertDirectoryExists(dir, path); var list = ListFiles(dir, recursive); @@ -472,7 +479,7 @@ namespace Emby.Common.Implementations.IO public IEnumerable GetFileSystemEntryPaths(string path, bool recursive = false) { - var dir = CreateSmbFile(path); + var dir = CreateSmbDirectoryForListFiles(path); AssertDirectoryExists(dir, path); var list = ListFiles(dir, recursive); @@ -485,7 +492,7 @@ namespace Emby.Common.Implementations.IO public IEnumerable GetFilePaths(string path, string[] extensions, bool enableCaseSensitiveExtensions, bool recursive = false) { - var dir = CreateSmbFile(path); + var dir = CreateSmbDirectoryForListFiles(path); AssertDirectoryExists(dir, path); var list = ListFiles(dir, recursive); @@ -507,7 +514,7 @@ namespace Emby.Common.Implementations.IO public IEnumerable GetDirectoryPaths(string path, bool recursive = false) { - var dir = CreateSmbFile(path); + var dir = CreateSmbDirectoryForListFiles(path); AssertDirectoryExists(dir, path); var list = ListFiles(dir, recursive); diff --git a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs index 6d15cc619..ee5245a69 100644 --- a/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs +++ b/Emby.Server.Implementations/HttpServer/HttpListenerHost.cs @@ -273,10 +273,19 @@ namespace Emby.Server.Implementations.HttpServer return 400; } + var exceptionType = ex.GetType(); + int statusCode; - if (!_mapExceptionToStatusCode.TryGetValue(ex.GetType(), out statusCode)) + if (!_mapExceptionToStatusCode.TryGetValue(exceptionType, out statusCode)) { - statusCode = 500; + if (string.Equals(exceptionType.Name, "DirectoryNotFoundException", StringComparison.OrdinalIgnoreCase)) + { + statusCode = 404; + } + else + { + statusCode = 500; + } } return statusCode; diff --git a/MediaBrowser.Model/IO/IFileSystem.cs b/MediaBrowser.Model/IO/IFileSystem.cs index 59e31debd..6773acbfa 100644 --- a/MediaBrowser.Model/IO/IFileSystem.cs +++ b/MediaBrowser.Model/IO/IFileSystem.cs @@ -312,7 +312,6 @@ namespace MediaBrowser.Model.IO void SetReadOnly(string path, bool isHidden); char DirectorySeparatorChar { get; } - char PathSeparator { get; } string GetFullPath(string path); -- cgit v1.2.3