From b3cf903a3ba2a88529178eefc4a119b70ba5236b Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Thu, 23 Mar 2023 17:34:19 -0700 Subject: [PATCH] New: Improve path validation when handling paths from different OSes (cherry picked from commit 0321368cc392d7a0a488409bf6bd586ba45497af) Closes #2309 --- .../EnsureTest/PathExtensionFixture.cs | 7 +- .../PathExtensionFixture.cs | 1 + src/NzbDrone.Common/Disk/DiskProviderBase.cs | 68 +++++++++---------- .../Disk/DiskTransferService.cs | 12 ++-- .../Disk/FileSystemLookupService.cs | 2 +- src/NzbDrone.Common/Disk/OsPath.cs | 3 +- .../Disk/PathValidationType.cs | 8 +++ .../EnsureThat/EnsureStringExtensions.cs | 5 +- .../Extensions/PathExtensions.cs | 26 ++++--- src/NzbDrone.Common/PathEqualityComparer.cs | 2 +- .../MediaFiles/BookFileMovingService.cs | 2 +- .../RootFolders/RootFolderService.cs | 2 +- .../Validation/FolderValidator.cs | 5 +- .../Validation/Paths/PathValidator.cs | 5 +- src/NzbDrone.Mono/Disk/DiskProvider.cs | 4 +- src/NzbDrone.Windows/Disk/DiskProvider.cs | 10 +-- 16 files changed, 92 insertions(+), 70 deletions(-) create mode 100644 src/NzbDrone.Common/Disk/PathValidationType.cs diff --git a/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs index fcad87fdd..4924725e1 100644 --- a/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/EnsureTest/PathExtensionFixture.cs @@ -1,4 +1,5 @@ -using NUnit.Framework; +using NUnit.Framework; +using NzbDrone.Common.Disk; using NzbDrone.Common.EnsureThat; using NzbDrone.Test.Common; @@ -12,14 +13,14 @@ namespace NzbDrone.Common.Test.EnsureTest public void EnsureWindowsPath(string path) { WindowsOnly(); - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); } [TestCase(@"/var/user/file with, comma.mp3")] public void EnsureLinuxPath(string path) { PosixOnly(); - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); } } } diff --git a/src/NzbDrone.Common.Test/PathExtensionFixture.cs b/src/NzbDrone.Common.Test/PathExtensionFixture.cs index 69a0417fe..a57a053ec 100644 --- a/src/NzbDrone.Common.Test/PathExtensionFixture.cs +++ b/src/NzbDrone.Common.Test/PathExtensionFixture.cs @@ -35,6 +35,7 @@ namespace NzbDrone.Common.Test [TestCase(@"\\Testserver\Test\file.ext", @"\\Testserver\Test\file.ext")] [TestCase(@"\\Testserver\Test\file.ext\\", @"\\Testserver\Test\file.ext")] [TestCase(@"\\Testserver\Test\file.ext \\", @"\\Testserver\Test\file.ext")] + [TestCase(@"//CAPITAL//lower// ", @"\\CAPITAL\lower")] public void Clean_Path_Windows(string dirty, string clean) { WindowsOnly(); diff --git a/src/NzbDrone.Common/Disk/DiskProviderBase.cs b/src/NzbDrone.Common/Disk/DiskProviderBase.cs index 22077527c..4e993c27a 100644 --- a/src/NzbDrone.Common/Disk/DiskProviderBase.cs +++ b/src/NzbDrone.Common/Disk/DiskProviderBase.cs @@ -72,7 +72,7 @@ namespace NzbDrone.Common.Disk private void CheckFolderExists(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); if (!FolderExists(path)) { @@ -82,7 +82,7 @@ namespace NzbDrone.Common.Disk private void CheckFileExists(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); if (!FileExists(path)) { @@ -100,19 +100,19 @@ namespace NzbDrone.Common.Disk public bool FolderExists(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.Directory.Exists(path); } public bool FileExists(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return FileExists(path, PathStringComparison); } public bool FileExists(string path, StringComparison stringComparison) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); switch (stringComparison) { @@ -132,7 +132,7 @@ namespace NzbDrone.Common.Disk public bool FolderWritable(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); try { @@ -151,42 +151,42 @@ namespace NzbDrone.Common.Disk public bool FolderEmpty(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.Directory.EnumerateFileSystemEntries(path).Empty(); } public string[] GetDirectories(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.Directory.GetDirectories(path); } public string[] GetDirectories(string path, SearchOption searchOption) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.Directory.GetDirectories(path, "*", searchOption); } public string[] GetFiles(string path, SearchOption searchOption) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.Directory.GetFiles(path, "*.*", searchOption); } public long GetFolderSize(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return GetFiles(path, SearchOption.AllDirectories).Sum(e => _fileSystem.FileInfo.FromFileName(e).Length); } public long GetFileSize(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); if (!FileExists(path)) { @@ -199,13 +199,13 @@ namespace NzbDrone.Common.Disk public void CreateFolder(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); _fileSystem.Directory.CreateDirectory(path); } public void DeleteFile(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); Logger.Trace("Deleting file: {0}", path); RemoveReadOnly(path); @@ -215,8 +215,8 @@ namespace NzbDrone.Common.Disk public void CloneFile(string source, string destination, bool overwrite = false) { - Ensure.That(source, () => source).IsValidPath(); - Ensure.That(destination, () => destination).IsValidPath(); + Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs); + Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs); if (source.PathEquals(destination)) { @@ -233,8 +233,8 @@ namespace NzbDrone.Common.Disk public void CopyFile(string source, string destination, bool overwrite = false) { - Ensure.That(source, () => source).IsValidPath(); - Ensure.That(destination, () => destination).IsValidPath(); + Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs); + Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs); if (source.PathEquals(destination)) { @@ -251,8 +251,8 @@ namespace NzbDrone.Common.Disk public void MoveFile(string source, string destination, bool overwrite = false) { - Ensure.That(source, () => source).IsValidPath(); - Ensure.That(destination, () => destination).IsValidPath(); + Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs); + Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs); if (source.PathEquals(destination)) { @@ -270,8 +270,8 @@ namespace NzbDrone.Common.Disk public void MoveFolder(string source, string destination) { - Ensure.That(source, () => source).IsValidPath(); - Ensure.That(destination, () => destination).IsValidPath(); + Ensure.That(source, () => source).IsValidPath(PathValidationType.CurrentOs); + Ensure.That(destination, () => destination).IsValidPath(PathValidationType.CurrentOs); Directory.Move(source, destination); } @@ -300,7 +300,7 @@ namespace NzbDrone.Common.Disk public void DeleteFolder(string path, bool recursive) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); var files = _fileSystem.Directory.GetFiles(path, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); Array.ForEach(files, RemoveReadOnly); @@ -310,14 +310,14 @@ namespace NzbDrone.Common.Disk public string ReadAllText(string filePath) { - Ensure.That(filePath, () => filePath).IsValidPath(); + Ensure.That(filePath, () => filePath).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.File.ReadAllText(filePath); } public void WriteAllText(string filename, string contents) { - Ensure.That(filename, () => filename).IsValidPath(); + Ensure.That(filename, () => filename).IsValidPath(PathValidationType.CurrentOs); RemoveReadOnly(filename); // File.WriteAllText is broken on net core when writing to some CIFS mounts @@ -333,14 +333,14 @@ namespace NzbDrone.Common.Disk public void FolderSetLastWriteTime(string path, DateTime dateTime) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); _fileSystem.Directory.SetLastWriteTimeUtc(path, dateTime); } public void FileSetLastWriteTime(string path, DateTime dateTime) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); _fileSystem.File.SetLastWriteTime(path, dateTime); } @@ -362,14 +362,14 @@ namespace NzbDrone.Common.Disk public string GetPathRoot(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return Path.GetPathRoot(path); } public string GetParentFolder(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); var parent = _fileSystem.Directory.GetParent(path.TrimEnd(Path.DirectorySeparatorChar)); @@ -402,7 +402,7 @@ namespace NzbDrone.Common.Disk public void EmptyFolder(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); foreach (var file in GetFiles(path, SearchOption.TopDirectoryOnly)) { @@ -491,7 +491,7 @@ namespace NzbDrone.Common.Disk public List GetDirectoryInfos(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); var di = _fileSystem.DirectoryInfo.FromDirectoryName(path); @@ -500,13 +500,13 @@ namespace NzbDrone.Common.Disk public IDirectoryInfo GetDirectoryInfo(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.DirectoryInfo.FromDirectoryName(path); } public List GetFileInfos(string path, SearchOption searchOption = SearchOption.TopDirectoryOnly) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); var di = _fileSystem.DirectoryInfo.FromDirectoryName(path); @@ -515,7 +515,7 @@ namespace NzbDrone.Common.Disk public IFileInfo GetFileInfo(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); return _fileSystem.FileInfo.FromFileName(path); } diff --git a/src/NzbDrone.Common/Disk/DiskTransferService.cs b/src/NzbDrone.Common/Disk/DiskTransferService.cs index 3a3a7771e..a9ea0ff8f 100644 --- a/src/NzbDrone.Common/Disk/DiskTransferService.cs +++ b/src/NzbDrone.Common/Disk/DiskTransferService.cs @@ -44,8 +44,8 @@ namespace NzbDrone.Common.Disk public TransferMode TransferFolder(string sourcePath, string targetPath, TransferMode mode) { - Ensure.That(sourcePath, () => sourcePath).IsValidPath(); - Ensure.That(targetPath, () => targetPath).IsValidPath(); + Ensure.That(sourcePath, () => sourcePath).IsValidPath(PathValidationType.CurrentOs); + Ensure.That(targetPath, () => targetPath).IsValidPath(PathValidationType.CurrentOs); sourcePath = ResolveRealParentPath(sourcePath); targetPath = ResolveRealParentPath(targetPath); @@ -141,8 +141,8 @@ namespace NzbDrone.Common.Disk { var filesCopied = 0; - Ensure.That(sourcePath, () => sourcePath).IsValidPath(); - Ensure.That(targetPath, () => targetPath).IsValidPath(); + Ensure.That(sourcePath, () => sourcePath).IsValidPath(PathValidationType.CurrentOs); + Ensure.That(targetPath, () => targetPath).IsValidPath(PathValidationType.CurrentOs); sourcePath = ResolveRealParentPath(sourcePath); targetPath = ResolveRealParentPath(targetPath); @@ -256,8 +256,8 @@ namespace NzbDrone.Common.Disk public TransferMode TransferFile(string sourcePath, string targetPath, TransferMode mode, bool overwrite = false) { - Ensure.That(sourcePath, () => sourcePath).IsValidPath(); - Ensure.That(targetPath, () => targetPath).IsValidPath(); + Ensure.That(sourcePath, () => sourcePath).IsValidPath(PathValidationType.CurrentOs); + Ensure.That(targetPath, () => targetPath).IsValidPath(PathValidationType.CurrentOs); sourcePath = ResolveRealParentPath(sourcePath); targetPath = ResolveRealParentPath(targetPath); diff --git a/src/NzbDrone.Common/Disk/FileSystemLookupService.cs b/src/NzbDrone.Common/Disk/FileSystemLookupService.cs index ae826bdce..427c4237e 100644 --- a/src/NzbDrone.Common/Disk/FileSystemLookupService.cs +++ b/src/NzbDrone.Common/Disk/FileSystemLookupService.cs @@ -71,7 +71,7 @@ namespace NzbDrone.Common.Disk if ( allowFoldersWithoutTrailingSlashes && - query.IsPathValid() && + query.IsPathValid(PathValidationType.CurrentOs) && _diskProvider.FolderExists(query)) { return GetResult(query, includeFiles); diff --git a/src/NzbDrone.Common/Disk/OsPath.cs b/src/NzbDrone.Common/Disk/OsPath.cs index 0cc853cb7..24c444fc3 100644 --- a/src/NzbDrone.Common/Disk/OsPath.cs +++ b/src/NzbDrone.Common/Disk/OsPath.cs @@ -1,6 +1,5 @@ using System; using System.Collections.Generic; -using System.Linq; using NzbDrone.Common.Extensions; namespace NzbDrone.Common.Disk @@ -162,7 +161,7 @@ namespace NzbDrone.Common.Disk } } - public bool IsValid => _path.IsPathValid(); + public bool IsValid => _path.IsPathValid(PathValidationType.CurrentOs); private int GetFileNameIndex() { diff --git a/src/NzbDrone.Common/Disk/PathValidationType.cs b/src/NzbDrone.Common/Disk/PathValidationType.cs new file mode 100644 index 000000000..395e3f0d8 --- /dev/null +++ b/src/NzbDrone.Common/Disk/PathValidationType.cs @@ -0,0 +1,8 @@ +namespace NzbDrone.Common.Disk +{ + public enum PathValidationType + { + CurrentOs, + AnyOs + } +} diff --git a/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs b/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs index 1c10c9f28..ba02ee7f6 100644 --- a/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs +++ b/src/NzbDrone.Common/EnsureThat/EnsureStringExtensions.cs @@ -1,5 +1,6 @@ using System.Diagnostics; using System.Text.RegularExpressions; +using NzbDrone.Common.Disk; using NzbDrone.Common.EnsureThat.Resources; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; @@ -111,14 +112,14 @@ namespace NzbDrone.Common.EnsureThat } [DebuggerStepThrough] - public static Param IsValidPath(this Param param) + public static Param IsValidPath(this Param param, PathValidationType validationType) { if (string.IsNullOrWhiteSpace(param.Value)) { throw ExceptionFactory.CreateForParamValidation(param.Name, ExceptionMessages.EnsureExtensions_IsNotNullOrWhiteSpace); } - if (param.Value.IsPathValid()) + if (param.Value.IsPathValid(validationType)) { return param; } diff --git a/src/NzbDrone.Common/Extensions/PathExtensions.cs b/src/NzbDrone.Common/Extensions/PathExtensions.cs index dc4b4005a..e4c18d849 100644 --- a/src/NzbDrone.Common/Extensions/PathExtensions.cs +++ b/src/NzbDrone.Common/Extensions/PathExtensions.cs @@ -31,7 +31,7 @@ namespace NzbDrone.Common.Extensions public static string CleanFilePath(this string path) { Ensure.That(path, () => path).IsNotNullOrWhiteSpace(); - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.AnyOs); var info = new FileInfo(path.Trim()); return info.FullName.CleanFilePathBasic(); @@ -40,7 +40,7 @@ namespace NzbDrone.Common.Extensions public static string CleanFilePathBasic(this string path) { //UNC - if (OsInfo.IsWindows && path.StartsWith(@"\\")) + if (!path.Contains('/') && path.StartsWith(@"\\")) { return path.TrimEnd('/', '\\', ' '); } @@ -138,24 +138,24 @@ namespace NzbDrone.Common.Extensions private static readonly Regex WindowsPathWithDriveRegex = new Regex(@"^[a-zA-Z]:\\", RegexOptions.Compiled); - public static bool IsPathValid(this string path) + public static bool IsPathValid(this string path, PathValidationType validationType) { if (path.ContainsInvalidPathChars() || string.IsNullOrWhiteSpace(path)) { return false; } - if (OsInfo.IsNotWindows) + if (validationType == PathValidationType.AnyOs) { - return path.StartsWith(Path.DirectorySeparatorChar.ToString()); + return IsPathValidForWindows(path) || IsPathValidForNonWindows(path); } - if (path.StartsWith("\\") || WindowsPathWithDriveRegex.IsMatch(path)) + if (OsInfo.IsNotWindows) { - return true; + return IsPathValidForNonWindows(path); } - return false; + return IsPathValidForWindows(path); } public static bool ContainsInvalidPathChars(this string text) @@ -371,5 +371,15 @@ namespace NzbDrone.Common.Extensions { return Path.Combine(appFolderInfo.StartUpFolder, NLOG_CONFIG_FILE); } + + private static bool IsPathValidForWindows(string path) + { + return path.StartsWith("\\") || WindowsPathWithDriveRegex.IsMatch(path); + } + + private static bool IsPathValidForNonWindows(string path) + { + return path.StartsWith("/"); + } } } diff --git a/src/NzbDrone.Common/PathEqualityComparer.cs b/src/NzbDrone.Common/PathEqualityComparer.cs index d443a3bf0..5b9c3aa1c 100644 --- a/src/NzbDrone.Common/PathEqualityComparer.cs +++ b/src/NzbDrone.Common/PathEqualityComparer.cs @@ -1,4 +1,4 @@ -using System.Collections.Generic; +using System.Collections.Generic; using NzbDrone.Common.EnvironmentInfo; using NzbDrone.Common.Extensions; diff --git a/src/NzbDrone.Core/MediaFiles/BookFileMovingService.cs b/src/NzbDrone.Core/MediaFiles/BookFileMovingService.cs index 62eef4472..83e2fa027 100644 --- a/src/NzbDrone.Core/MediaFiles/BookFileMovingService.cs +++ b/src/NzbDrone.Core/MediaFiles/BookFileMovingService.cs @@ -104,7 +104,7 @@ namespace NzbDrone.Core.MediaFiles { Ensure.That(bookFile, () => bookFile).IsNotNull(); Ensure.That(author, () => author).IsNotNull(); - Ensure.That(destinationFilePath, () => destinationFilePath).IsValidPath(); + Ensure.That(destinationFilePath, () => destinationFilePath).IsValidPath(PathValidationType.CurrentOs); var bookFilePath = bookFile.Path; diff --git a/src/NzbDrone.Core/RootFolders/RootFolderService.cs b/src/NzbDrone.Core/RootFolders/RootFolderService.cs index e69c1c06d..b3870283e 100644 --- a/src/NzbDrone.Core/RootFolders/RootFolderService.cs +++ b/src/NzbDrone.Core/RootFolders/RootFolderService.cs @@ -63,7 +63,7 @@ namespace NzbDrone.Core.RootFolders { try { - if (folder.Path.IsPathValid()) + if (folder.Path.IsPathValid(PathValidationType.CurrentOs)) { GetDetails(folder); } diff --git a/src/NzbDrone.Core/Validation/FolderValidator.cs b/src/NzbDrone.Core/Validation/FolderValidator.cs index 9eedeb459..9d327b9c6 100644 --- a/src/NzbDrone.Core/Validation/FolderValidator.cs +++ b/src/NzbDrone.Core/Validation/FolderValidator.cs @@ -1,4 +1,5 @@ -using FluentValidation.Validators; +using FluentValidation.Validators; +using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; namespace NzbDrone.Core.Validation @@ -17,7 +18,7 @@ namespace NzbDrone.Core.Validation return false; } - return context.PropertyValue.ToString().IsPathValid(); + return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs); } } } diff --git a/src/NzbDrone.Core/Validation/Paths/PathValidator.cs b/src/NzbDrone.Core/Validation/Paths/PathValidator.cs index c546d3e79..40ca0579f 100644 --- a/src/NzbDrone.Core/Validation/Paths/PathValidator.cs +++ b/src/NzbDrone.Core/Validation/Paths/PathValidator.cs @@ -1,5 +1,6 @@ -using FluentValidation; +using FluentValidation; using FluentValidation.Validators; +using NzbDrone.Common.Disk; using NzbDrone.Common.Extensions; namespace NzbDrone.Core.Validation.Paths @@ -26,7 +27,7 @@ namespace NzbDrone.Core.Validation.Paths return false; } - return context.PropertyValue.ToString().IsPathValid(); + return context.PropertyValue.ToString().IsPathValid(PathValidationType.CurrentOs); } } } diff --git a/src/NzbDrone.Mono/Disk/DiskProvider.cs b/src/NzbDrone.Mono/Disk/DiskProvider.cs index e369ea146..3c0a494ef 100644 --- a/src/NzbDrone.Mono/Disk/DiskProvider.cs +++ b/src/NzbDrone.Mono/Disk/DiskProvider.cs @@ -57,7 +57,7 @@ namespace NzbDrone.Mono.Disk public override long? GetAvailableSpace(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); Logger.Debug($"path: {path}"); @@ -218,7 +218,7 @@ namespace NzbDrone.Mono.Disk public override long? GetTotalSize(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); var mount = GetMount(path); diff --git a/src/NzbDrone.Windows/Disk/DiskProvider.cs b/src/NzbDrone.Windows/Disk/DiskProvider.cs index f480eaf36..55a2efbaa 100644 --- a/src/NzbDrone.Windows/Disk/DiskProvider.cs +++ b/src/NzbDrone.Windows/Disk/DiskProvider.cs @@ -39,7 +39,7 @@ namespace NzbDrone.Windows.Disk public override long? GetAvailableSpace(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); var root = GetPathRoot(path); @@ -53,7 +53,7 @@ namespace NzbDrone.Windows.Disk public override void InheritFolderPermissions(string filename) { - Ensure.That(filename, () => filename).IsValidPath(); + Ensure.That(filename, () => filename).IsValidPath(PathValidationType.CurrentOs); var fileInfo = new FileInfo(filename); var fs = fileInfo.GetAccessControl(AccessControlSections.Access); @@ -116,7 +116,7 @@ namespace NzbDrone.Windows.Disk public override long? GetTotalSize(string path) { - Ensure.That(path, () => path).IsValidPath(); + Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); var root = GetPathRoot(path); @@ -130,7 +130,7 @@ namespace NzbDrone.Windows.Disk private static long DriveFreeSpaceEx(string folderName) { - Ensure.That(folderName, () => folderName).IsValidPath(); + Ensure.That(folderName, () => folderName).IsValidPath(PathValidationType.CurrentOs); if (!folderName.EndsWith("\\")) { @@ -151,7 +151,7 @@ namespace NzbDrone.Windows.Disk private static long DriveTotalSizeEx(string folderName) { - Ensure.That(folderName, () => folderName).IsValidPath(); + Ensure.That(folderName, () => folderName).IsValidPath(PathValidationType.CurrentOs); if (!folderName.EndsWith("\\")) {