From f917d0e9bced2b2e7b06d35a579e354be578c131 Mon Sep 17 00:00:00 2001 From: ta264 Date: Wed, 7 Oct 2020 21:06:03 +0100 Subject: [PATCH] Add FileInfo utility functions to DiskProvider --- .../DiskTests/DiskTransferServiceFixture.cs | 6 +++--- src/NzbDrone.Common/Disk/DiskProviderBase.cs | 11 +++++++++-- src/NzbDrone.Common/Disk/IDiskProvider.cs | 3 ++- 3 files changed, 14 insertions(+), 6 deletions(-) diff --git a/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs b/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs index 971bb21d4..1672fe0d4 100644 --- a/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs +++ b/src/NzbDrone.Common.Test/DiskTests/DiskTransferServiceFixture.cs @@ -731,7 +731,7 @@ private void WithEmulatedDiskProvider() // Note: never returns anything. Mocker.GetMock() - .Setup(v => v.GetFileInfos(It.IsAny())) + .Setup(v => v.GetFileInfos(It.IsAny(), SearchOption.TopDirectoryOnly)) .Returns(new List()); Mocker.GetMock() @@ -765,8 +765,8 @@ private void WithRealDiskProvider() .Returns(v => new DirectoryInfo(v).GetDirectories().ToList()); Mocker.GetMock() - .Setup(v => v.GetFileInfos(It.IsAny())) - .Returns(v => new DirectoryInfo(v).GetFiles().ToList()); + .Setup(v => v.GetFileInfos(It.IsAny(), SearchOption.TopDirectoryOnly)) + .Returns((v, _) => new DirectoryInfo(v).GetFiles().ToList()); Mocker.GetMock() .Setup(v => v.GetFileSize(It.IsAny())) diff --git a/src/NzbDrone.Common/Disk/DiskProviderBase.cs b/src/NzbDrone.Common/Disk/DiskProviderBase.cs index c8dfe92b3..32b046b58 100644 --- a/src/NzbDrone.Common/Disk/DiskProviderBase.cs +++ b/src/NzbDrone.Common/Disk/DiskProviderBase.cs @@ -505,13 +505,20 @@ public List GetDirectoryInfos(string path) return di.GetDirectories().ToList(); } - public List GetFileInfos(string path) + public FileInfo GetFileInfo(string path) + { + Ensure.That(path, () => path).IsValidPath(); + + return new FileInfo(path); + } + + public List GetFileInfos(string path, SearchOption searchOption = SearchOption.TopDirectoryOnly) { Ensure.That(path, () => path).IsValidPath(); var di = new DirectoryInfo(path); - return di.GetFiles().ToList(); + return di.GetFiles("*", searchOption).ToList(); } public void RemoveEmptySubfolders(string path) diff --git a/src/NzbDrone.Common/Disk/IDiskProvider.cs b/src/NzbDrone.Common/Disk/IDiskProvider.cs index f90d12989..cb262504a 100644 --- a/src/NzbDrone.Common/Disk/IDiskProvider.cs +++ b/src/NzbDrone.Common/Disk/IDiskProvider.cs @@ -52,7 +52,8 @@ public interface IDiskProvider List GetMounts(); IMount GetMount(string path); List GetDirectoryInfos(string path); - List GetFileInfos(string path); + FileInfo GetFileInfo(string path); + List GetFileInfos(string path, SearchOption searchOption = SearchOption.TopDirectoryOnly); void RemoveEmptySubfolders(string path); void SaveStream(Stream stream, string path); bool IsValidFilePermissionMask(string mask);