aboutsummaryrefslogtreecommitdiff
path: root/Emby.Server.Implementations/IO/ManagedFileSystem.cs
diff options
context:
space:
mode:
authorShadowghost <Ghost_of_Stone@web.de>2022-12-07 17:40:24 +0100
committerShadowghost <Ghost_of_Stone@web.de>2022-12-07 17:40:24 +0100
commit2c86bd1875e6e85d5867618e992d850453dae663 (patch)
tree671070fb246fd3821bf6f1e58a01c402a2f969d1 /Emby.Server.Implementations/IO/ManagedFileSystem.cs
parentdd5f90802e71083347b6095eb79a9de0b9d34615 (diff)
parent3cb7fe50127b1a8158186b390836ee25ae5a50fd (diff)
Merge branch 'master' into network-rewrite
Diffstat (limited to 'Emby.Server.Implementations/IO/ManagedFileSystem.cs')
-rw-r--r--Emby.Server.Implementations/IO/ManagedFileSystem.cs58
1 files changed, 14 insertions, 44 deletions
diff --git a/Emby.Server.Implementations/IO/ManagedFileSystem.cs b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
index 120b1812a..55f384ae8 100644
--- a/Emby.Server.Implementations/IO/ManagedFileSystem.cs
+++ b/Emby.Server.Implementations/IO/ManagedFileSystem.cs
@@ -48,10 +48,7 @@ namespace Emby.Server.Implementations.IO
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is <c>null</c>.</exception>
public virtual bool IsShortcut(string filename)
{
- if (string.IsNullOrEmpty(filename))
- {
- throw new ArgumentNullException(nameof(filename));
- }
+ ArgumentException.ThrowIfNullOrEmpty(filename);
var extension = Path.GetExtension(filename);
return _shortcutHandlers.Any(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
@@ -65,10 +62,7 @@ namespace Emby.Server.Implementations.IO
/// <exception cref="ArgumentNullException"><paramref name="filename"/> is <c>null</c>.</exception>
public virtual string? ResolveShortcut(string filename)
{
- if (string.IsNullOrEmpty(filename))
- {
- throw new ArgumentNullException(nameof(filename));
- }
+ ArgumentException.ThrowIfNullOrEmpty(filename);
var extension = Path.GetExtension(filename);
var handler = _shortcutHandlers.Find(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
@@ -136,20 +130,13 @@ namespace Emby.Server.Implementations.IO
/// <exception cref="ArgumentNullException">The shortcutPath or target is null.</exception>
public virtual void CreateShortcut(string shortcutPath, string target)
{
- if (string.IsNullOrEmpty(shortcutPath))
- {
- throw new ArgumentNullException(nameof(shortcutPath));
- }
-
- if (string.IsNullOrEmpty(target))
- {
- throw new ArgumentNullException(nameof(target));
- }
+ ArgumentException.ThrowIfNullOrEmpty(shortcutPath);
+ ArgumentException.ThrowIfNullOrEmpty(target);
var extension = Path.GetExtension(shortcutPath);
var handler = _shortcutHandlers.Find(i => string.Equals(extension, i.Extension, StringComparison.OrdinalIgnoreCase));
- if (handler != null)
+ if (handler is not null)
{
handler.Create(shortcutPath, target);
}
@@ -488,15 +475,8 @@ namespace Emby.Server.Implementations.IO
/// <param name="file2">The file2.</param>
public virtual void SwapFiles(string file1, string file2)
{
- if (string.IsNullOrEmpty(file1))
- {
- throw new ArgumentNullException(nameof(file1));
- }
-
- if (string.IsNullOrEmpty(file2))
- {
- throw new ArgumentNullException(nameof(file2));
- }
+ ArgumentException.ThrowIfNullOrEmpty(file1);
+ ArgumentException.ThrowIfNullOrEmpty(file2);
var temp1 = Path.Combine(_tempPath, Guid.NewGuid().ToString("N", CultureInfo.InvariantCulture));
@@ -514,15 +494,8 @@ namespace Emby.Server.Implementations.IO
/// <inheritdoc />
public virtual bool ContainsSubPath(string parentPath, string path)
{
- if (string.IsNullOrEmpty(parentPath))
- {
- throw new ArgumentNullException(nameof(parentPath));
- }
-
- if (string.IsNullOrEmpty(path))
- {
- throw new ArgumentNullException(nameof(path));
- }
+ ArgumentException.ThrowIfNullOrEmpty(parentPath);
+ ArgumentException.ThrowIfNullOrEmpty(path);
return path.Contains(
Path.TrimEndingDirectorySeparator(parentPath) + Path.DirectorySeparatorChar,
@@ -532,10 +505,7 @@ namespace Emby.Server.Implementations.IO
/// <inheritdoc />
public virtual string NormalizePath(string path)
{
- if (string.IsNullOrEmpty(path))
- {
- throw new ArgumentNullException(nameof(path));
- }
+ ArgumentException.ThrowIfNullOrEmpty(path);
if (path.EndsWith(":\\", StringComparison.OrdinalIgnoreCase))
{
@@ -621,14 +591,14 @@ namespace Emby.Server.Implementations.IO
// On linux and osx the search pattern is case sensitive
// If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
- if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Count == 1)
+ if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions is not null && extensions.Count == 1)
{
return ToMetadata(new DirectoryInfo(path).EnumerateFiles("*" + extensions[0], enumerationOptions));
}
var files = new DirectoryInfo(path).EnumerateFiles("*", enumerationOptions);
- if (extensions != null && extensions.Count > 0)
+ if (extensions is not null && extensions.Count > 0)
{
files = files.Where(i =>
{
@@ -678,14 +648,14 @@ namespace Emby.Server.Implementations.IO
// On linux and osx the search pattern is case sensitive
// If we're OK with case-sensitivity, and we're only filtering for one extension, then use the native method
- if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions != null && extensions.Length == 1)
+ if ((enableCaseSensitiveExtensions || _isEnvironmentCaseInsensitive) && extensions is not null && extensions.Length == 1)
{
return Directory.EnumerateFiles(path, "*" + extensions[0], enumerationOptions);
}
var files = Directory.EnumerateFiles(path, "*", enumerationOptions);
- if (extensions != null && extensions.Length > 0)
+ if (extensions is not null && extensions.Length > 0)
{
files = files.Where(i =>
{