diff --git a/src/NzbDrone.Common/ArchiveService.cs b/src/NzbDrone.Common/ArchiveService.cs index 12b54da36..1f06719c5 100644 --- a/src/NzbDrone.Common/ArchiveService.cs +++ b/src/NzbDrone.Common/ArchiveService.cs @@ -1,4 +1,5 @@ using System; +using System.Collections.Generic; using System.IO; using ICSharpCode.SharpZipLib.Core; using ICSharpCode.SharpZipLib.GZip; @@ -11,7 +12,7 @@ namespace NzbDrone.Common public interface IArchiveService { void Extract(string compressedFile, string destination); - void CreateZip(string path, params string[] files); + void CreateZip(string path, IEnumerable files); } public class ArchiveService : IArchiveService @@ -39,7 +40,7 @@ namespace NzbDrone.Common _logger.Debug("Extraction complete."); } - public void CreateZip(string path, params string[] files) + public void CreateZip(string path, IEnumerable files) { using (var zipFile = ZipFile.Create(path)) { diff --git a/src/NzbDrone.Common/Disk/DiskProviderBase.cs b/src/NzbDrone.Common/Disk/DiskProviderBase.cs index 283162bfd..86d95eda3 100644 --- a/src/NzbDrone.Common/Disk/DiskProviderBase.cs +++ b/src/NzbDrone.Common/Disk/DiskProviderBase.cs @@ -46,7 +46,7 @@ namespace NzbDrone.Common.Disk { CheckFolderExists(path); - var dirFiles = GetFiles(path, SearchOption.AllDirectories).ToList(); + var dirFiles = GetFiles(path, true).ToList(); if (!dirFiles.Any()) { @@ -149,25 +149,29 @@ namespace NzbDrone.Common.Disk return Directory.EnumerateFileSystemEntries(path).Empty(); } - public string[] GetDirectories(string path) + public IEnumerable GetDirectories(string path) { Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); - return Directory.GetDirectories(path); + return Directory.EnumerateDirectories(path); } - public string[] GetFiles(string path, SearchOption searchOption) + public IEnumerable GetFiles(string path, bool recursive) { Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); - return Directory.GetFiles(path, "*.*", searchOption); + return Directory.EnumerateFiles(path, "*", new EnumerationOptions + { + RecurseSubdirectories = recursive, + IgnoreInaccessible = true + }); } public long GetFolderSize(string path) { Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); - return GetFiles(path, SearchOption.AllDirectories).Sum(e => new FileInfo(e).Length); + return GetFiles(path, true).Sum(e => new FileInfo(e).Length); } public long GetFileSize(string path) @@ -288,8 +292,9 @@ namespace NzbDrone.Common.Disk { Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); - var files = Directory.GetFiles(path, "*.*", recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly); - Array.ForEach(files, RemoveReadOnly); + var files = GetFiles(path, recursive); + + files.ToList().ForEach(RemoveReadOnly); Directory.Delete(path, recursive); } @@ -381,7 +386,7 @@ namespace NzbDrone.Common.Disk { Ensure.That(path, () => path).IsValidPath(PathValidationType.CurrentOs); - foreach (var file in GetFiles(path, SearchOption.TopDirectoryOnly)) + foreach (var file in GetFiles(path, false)) { DeleteFile(file); } diff --git a/src/NzbDrone.Common/Disk/IDiskProvider.cs b/src/NzbDrone.Common/Disk/IDiskProvider.cs index 8d6d62e84..ffce3cc3b 100644 --- a/src/NzbDrone.Common/Disk/IDiskProvider.cs +++ b/src/NzbDrone.Common/Disk/IDiskProvider.cs @@ -22,8 +22,8 @@ namespace NzbDrone.Common.Disk bool FileExists(string path, StringComparison stringComparison); bool FolderWritable(string path); bool FolderEmpty(string path); - string[] GetDirectories(string path); - string[] GetFiles(string path, SearchOption searchOption); + IEnumerable GetDirectories(string path); + IEnumerable GetFiles(string path, bool recursive); long GetFolderSize(string path); long GetFileSize(string path); void CreateFolder(string path); diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs index 95f8dff2b..3876ecf4d 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/ScanWatchFolderFixture.cs @@ -29,7 +29,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole .Returns(new[] { targetDir }); Mocker.GetMock() - .Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories)) + .Setup(c => c.GetFiles(targetDir, true)) .Returns(new[] { Path.Combine(targetDir, "somefile.mkv") }); Mocker.GetMock() diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs index 15e25e2b9..3f9ca1f70 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/TorrentBlackholeFixture.cs @@ -78,7 +78,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole .Returns(new[] { targetDir }); Mocker.GetMock() - .Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories)) + .Setup(c => c.GetFiles(targetDir, true)) .Returns(new[] { Path.Combine(targetDir, "somefile.mkv") }); Mocker.GetMock() diff --git a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs index c9a3a3fb0..3d21af2ba 100644 --- a/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs +++ b/src/NzbDrone.Core.Test/Download/DownloadClientTests/Blackhole/UsenetBlackholeFixture.cs @@ -70,7 +70,7 @@ namespace NzbDrone.Core.Test.Download.DownloadClientTests.Blackhole .Returns(new[] { targetDir }); Mocker.GetMock() - .Setup(c => c.GetFiles(targetDir, SearchOption.AllDirectories)) + .Setup(c => c.GetFiles(targetDir, true)) .Returns(new[] { Path.Combine(targetDir, "somefile.mkv") }); Mocker.GetMock() diff --git a/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs b/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs index 25ed38a3f..5c0c42271 100644 --- a/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Extras/ExtraServiceFixture.cs @@ -121,7 +121,7 @@ namespace NzbDrone.Core.Test.Extras WithExistingFile(file); } - Mocker.GetMock().Setup(s => s.GetFiles(_episodeFolder, It.IsAny())) + Mocker.GetMock().Setup(s => s.GetFiles(_episodeFolder, It.IsAny())) .Returns(files.ToArray()); } @@ -224,8 +224,8 @@ namespace NzbDrone.Core.Test.Extras Subject.ImportEpisode(_localEpisode, _episodeFile, true); - Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.AllDirectories), Times.Once); - Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.TopDirectoryOnly), Times.Never); + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, true), Times.Once); + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, false), Times.Never); } [Test] @@ -245,8 +245,8 @@ namespace NzbDrone.Core.Test.Extras Subject.ImportEpisode(_localEpisode, _episodeFile, true); - Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.AllDirectories), Times.Never); - Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, SearchOption.TopDirectoryOnly), Times.Once); + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, true), Times.Never); + Mocker.GetMock().Verify(v => v.GetFiles(_episodeFolder, false), Times.Once); } } } diff --git a/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs b/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs index cdfac939c..64adecdeb 100644 --- a/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs +++ b/src/NzbDrone.Core.Test/Extras/Subtitles/SubtitleServiceFixture.cs @@ -170,7 +170,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles sampleFile }; - Mocker.GetMock().Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + Mocker.GetMock().Setup(s => s.GetFiles(It.IsAny(), true)) .Returns(videoFiles); Mocker.GetMock().Setup(s => s.IsSample(It.IsAny(), sampleFile, It.IsAny())) @@ -198,7 +198,7 @@ namespace NzbDrone.Core.Test.Extras.Subtitles Path.Combine(_series.Path, "Season 1", "Series Title - S01E01.sample.mkv").AsOsAgnostic() }; - Mocker.GetMock().Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + Mocker.GetMock().Setup(s => s.GetFiles(It.IsAny(), true)) .Returns(videoFiles); var results = Subject.ImportFiles(_localEpisode, _episodeFile, new List { subtitleFile }, true).ToList(); diff --git a/src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs index f1df64240..cd9da2e05 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/DiskScanServiceTests/ScanFixture.cs @@ -81,7 +81,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests private void GivenFiles(IEnumerable files) { Mocker.GetMock() - .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Setup(s => s.GetFiles(It.IsAny(), true)) .Returns(files.ToArray()); } @@ -93,7 +93,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests ExceptionVerification.ExpectedWarns(1); Mocker.GetMock() - .Verify(v => v.GetFiles(_series.Path, SearchOption.AllDirectories), Times.Never()); + .Verify(v => v.GetFiles(_series.Path, true), Times.Never()); Mocker.GetMock() .Verify(v => v.CreateFolder(_series.Path), Times.Never()); @@ -112,7 +112,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests ExceptionVerification.ExpectedWarns(1); Mocker.GetMock() - .Verify(v => v.GetFiles(_series.Path, SearchOption.AllDirectories), Times.Never()); + .Verify(v => v.GetFiles(_series.Path, true), Times.Never()); Mocker.GetMock() .Verify(v => v.CreateFolder(_series.Path), Times.Never()); @@ -267,7 +267,7 @@ namespace NzbDrone.Core.Test.MediaFiles.DiskScanServiceTests Subject.Scan(_series); Mocker.GetMock() - .Verify(v => v.GetFiles(It.IsAny(), It.IsAny()), Times.Once()); + .Verify(v => v.GetFiles(It.IsAny(), It.IsAny()), Times.Once()); Mocker.GetMock() .Verify(v => v.GetImportDecisions(It.Is>(l => l.Count == 1), _series, false), Times.Once()); diff --git a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs index 1e3e36c89..892c3b65e 100644 --- a/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs +++ b/src/NzbDrone.Core.Test/MediaFiles/DownloadedEpisodesImportServiceFixture.cs @@ -284,7 +284,7 @@ namespace NzbDrone.Core.Test.MediaFiles .Returns(DetectSampleResult.Sample); Mocker.GetMock() - .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Setup(s => s.GetFiles(It.IsAny(), true)) .Returns(new[] { _videoFiles.First().Replace(".ext", ".rar") }); Mocker.GetMock() @@ -310,7 +310,7 @@ namespace NzbDrone.Core.Test.MediaFiles Mocker.GetMock().Setup(c => c.FolderExists(folderName)) .Returns(true); - Mocker.GetMock().Setup(c => c.GetFiles(folderName, SearchOption.TopDirectoryOnly)) + Mocker.GetMock().Setup(c => c.GetFiles(folderName, false)) .Returns(new[] { fileName }); var localEpisode = new LocalEpisode(); @@ -463,7 +463,7 @@ namespace NzbDrone.Core.Test.MediaFiles .Returns(imported.Select(i => new ImportResult(i)).ToList()); Mocker.GetMock() - .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Setup(s => s.GetFiles(It.IsAny(), true)) .Returns(new[] { _videoFiles.First().Replace(".ext", ".rar") }); var result = Subject.ProcessPath(path); @@ -489,7 +489,7 @@ namespace NzbDrone.Core.Test.MediaFiles .Returns(imported.Select(i => new ImportResult(i)).ToList()); Mocker.GetMock() - .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Setup(s => s.GetFiles(It.IsAny(), true)) .Returns(new[] { _videoFiles.First().Replace(".ext", ".exe") }); var result = Subject.ProcessPath(path); diff --git a/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs b/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs index 43b779b2b..e9edf3f38 100644 --- a/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs +++ b/src/NzbDrone.Core.Test/ProviderTests/DiskScanProviderTests/GetVideoFilesFixture.cs @@ -37,7 +37,7 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests { var filesToReturn = files.ToArray(); Mocker.GetMock() - .Setup(s => s.GetFiles(It.IsAny(), SearchOption.AllDirectories)) + .Setup(s => s.GetFiles(It.IsAny(), true)) .Returns(filesToReturn); } @@ -48,8 +48,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Subject.GetVideoFiles(path); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); + Mocker.GetMock().Verify(s => s.GetFiles(path, true), Times.Once()); + Mocker.GetMock().Verify(s => s.GetFiles(path, false), Times.Never()); } [Test] @@ -59,8 +59,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Subject.GetVideoFiles(path, true); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Once()); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Never()); + Mocker.GetMock().Verify(s => s.GetFiles(path, true), Times.Once()); + Mocker.GetMock().Verify(s => s.GetFiles(path, false), Times.Never()); } [Test] @@ -70,8 +70,8 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskScanProviderTests Subject.GetVideoFiles(path, false); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.AllDirectories), Times.Never()); - Mocker.GetMock().Verify(s => s.GetFiles(path, SearchOption.TopDirectoryOnly), Times.Once()); + Mocker.GetMock().Verify(s => s.GetFiles(path, true), Times.Never()); + Mocker.GetMock().Verify(s => s.GetFiles(path, false), Times.Once()); } [Test] diff --git a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs index 7fb282fa2..2ec41f3a4 100644 --- a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs +++ b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; @@ -42,7 +41,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.GetMock().Setup(s => s.GetDirectories(RecycleBin)) .Returns(new[] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" }); - Mocker.GetMock().Setup(s => s.GetFiles(RecycleBin, SearchOption.AllDirectories)) + Mocker.GetMock().Setup(s => s.GetFiles(RecycleBin, true)) .Returns(new[] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" }); } diff --git a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs index 433e6f3a6..34893e233 100644 --- a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs +++ b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/DeleteDirectoryFixture.cs @@ -1,5 +1,4 @@ -using System; -using System.IO; +using System; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; @@ -68,7 +67,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests WithRecycleBin(); var path = @"C:\Test\TV\30 Rock".AsOsAgnostic(); - Mocker.GetMock().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock".AsOsAgnostic(), SearchOption.AllDirectories)) + Mocker.GetMock().Setup(s => s.GetFiles(@"C:\Test\Recycle Bin\30 Rock".AsOsAgnostic(), true)) .Returns(new[] { "File1", "File2", "File3" }); Mocker.Resolve().DeleteFolder(path); diff --git a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs index f061c1388..2b1a8ffa1 100644 --- a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs +++ b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/EmptyFixture.cs @@ -1,4 +1,3 @@ -using System.IO; using Moq; using NUnit.Framework; using NzbDrone.Common.Disk; @@ -22,7 +21,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.GetMock().Setup(s => s.GetDirectories(RecycleBin)) .Returns(new[] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" }); - Mocker.GetMock().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly)) + Mocker.GetMock().Setup(s => s.GetFiles(RecycleBin, false)) .Returns(new[] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" }); } diff --git a/src/NzbDrone.Core/Backup/BackupService.cs b/src/NzbDrone.Core/Backup/BackupService.cs index 385a5690b..56f1fe23c 100644 --- a/src/NzbDrone.Core/Backup/BackupService.cs +++ b/src/NzbDrone.Core/Backup/BackupService.cs @@ -89,7 +89,7 @@ namespace NzbDrone.Core.Backup // Delete journal file created during database backup _diskProvider.DeleteFile(Path.Combine(_backupTempFolder, "sonarr.db-journal")); - _archiveService.CreateZip(backupPath, _diskProvider.GetFiles(_backupTempFolder, SearchOption.TopDirectoryOnly)); + _archiveService.CreateZip(backupPath, _diskProvider.GetFiles(_backupTempFolder, false)); _logger.ProgressDebug("Backup zip created"); } @@ -126,7 +126,7 @@ namespace NzbDrone.Core.Backup _archiveService.Extract(backupFileName, temporaryPath); - foreach (var file in _diskProvider.GetFiles(temporaryPath, SearchOption.TopDirectoryOnly)) + foreach (var file in _diskProvider.GetFiles(temporaryPath, false)) { var fileName = Path.GetFileName(file); @@ -238,7 +238,7 @@ namespace NzbDrone.Core.Backup private IEnumerable GetBackupFiles(string path) { - var files = _diskProvider.GetFiles(path, SearchOption.TopDirectoryOnly); + var files = _diskProvider.GetFiles(path, false); return files.Where(f => BackupFileRegex.IsMatch(f)); } diff --git a/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs b/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs index 3b7ad1edf..a4a3c7c73 100644 --- a/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs +++ b/src/NzbDrone.Core/Download/Clients/Blackhole/ScanWatchFolder.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using System.Linq; @@ -69,7 +69,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole if (PreCheckWatchItemExpiry(newWatchItem, oldWatchItem)) { - var files = _diskProvider.GetFiles(folder, SearchOption.AllDirectories); + var files = _diskProvider.GetFiles(folder, true); newWatchItem.TotalSize = files.Select(_diskProvider.GetFileSize).Sum(); newWatchItem.Hash = GetHash(folder, files); @@ -153,7 +153,7 @@ namespace NzbDrone.Core.Download.Clients.Blackhole } } - private string GetHash(string folder, string[] files) + private string GetHash(string folder, IEnumerable files) { var data = new StringBuilder(); diff --git a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs index 298de88e2..4a2ba37b9 100644 --- a/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs +++ b/src/NzbDrone.Core/Download/Clients/Pneumatic/Pneumatic.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.Collections.Generic; using System.IO; using FluentValidation.Results; @@ -61,7 +61,7 @@ namespace NzbDrone.Core.Download.Clients.Pneumatic public override IEnumerable GetItems() { - foreach (var file in _diskProvider.GetFiles(Settings.StrmFolder, SearchOption.TopDirectoryOnly)) + foreach (var file in _diskProvider.GetFiles(Settings.StrmFolder, false)) { if (Path.GetExtension(file) != ".strm") { diff --git a/src/NzbDrone.Core/Extras/ExtraService.cs b/src/NzbDrone.Core/Extras/ExtraService.cs index 46c2b9024..eca970898 100644 --- a/src/NzbDrone.Core/Extras/ExtraService.cs +++ b/src/NzbDrone.Core/Extras/ExtraService.cs @@ -60,9 +60,7 @@ namespace NzbDrone.Core.Extras return; } - var folderSearchOption = localEpisode.FolderEpisodeInfo == null - ? SearchOption.TopDirectoryOnly - : SearchOption.AllDirectories; + var folderSearchOption = localEpisode.FolderEpisodeInfo != null; var wantedExtensions = _configService.ExtraFileExtensions.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries) .Select(e => e.Trim(' ', '.') diff --git a/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs b/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs index b7bbe8ea6..a984c2d34 100644 --- a/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs +++ b/src/NzbDrone.Core/Extras/Subtitles/SubtitleService.cs @@ -145,7 +145,7 @@ namespace NzbDrone.Core.Extras.Subtitles // Use any sub if only episode in folder if (matchingFiles.Count == 0 && filteredFiles.Count > 0) { - var videoFiles = _diskProvider.GetFiles(sourceFolder, SearchOption.AllDirectories) + var videoFiles = _diskProvider.GetFiles(sourceFolder, true) .Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file))) .ToList(); diff --git a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs index 4910eadb9..589a5c1c4 100644 --- a/src/NzbDrone.Core/MediaFiles/DiskScanService.cs +++ b/src/NzbDrone.Core/MediaFiles/DiskScanService.cs @@ -194,8 +194,7 @@ namespace NzbDrone.Core.MediaFiles { _logger.Debug("Scanning '{0}' for video files", path); - var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - var filesOnDisk = _diskProvider.GetFiles(path, searchOption).ToList(); + var filesOnDisk = _diskProvider.GetFiles(path, allDirectories).ToList(); var mediaFileList = filesOnDisk.Where(file => MediaFileExtensions.Extensions.Contains(Path.GetExtension(file))) .ToList(); @@ -210,8 +209,7 @@ namespace NzbDrone.Core.MediaFiles { _logger.Debug("Scanning '{0}' for non-video files", path); - var searchOption = allDirectories ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly; - var filesOnDisk = _diskProvider.GetFiles(path, searchOption).ToList(); + var filesOnDisk = _diskProvider.GetFiles(path, allDirectories).ToList(); var mediaFileList = filesOnDisk.Where(file => !MediaFileExtensions.Extensions.Contains(Path.GetExtension(file))) .ToList(); diff --git a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs index c08666a5b..be2a6ff5a 100644 --- a/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs +++ b/src/NzbDrone.Core/MediaFiles/DownloadedEpisodesImportService.cs @@ -111,7 +111,7 @@ namespace NzbDrone.Core.MediaFiles try { var videoFiles = _diskScanService.GetVideoFiles(directoryInfo.FullName); - var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, SearchOption.AllDirectories).Where(f => + var rarFiles = _diskProvider.GetFiles(directoryInfo.FullName, true).Where(f => Path.GetExtension(f).Equals(".rar", StringComparison.OrdinalIgnoreCase)); @@ -309,7 +309,7 @@ namespace NzbDrone.Core.MediaFiles private ImportResult CheckEmptyResultForIssue(string folder) { - var files = _diskProvider.GetFiles(folder, SearchOption.AllDirectories); + var files = _diskProvider.GetFiles(folder, true); if (files.Any(file => FileExtensions.ExecutableExtensions.Contains(Path.GetExtension(file)))) { diff --git a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index 4e03616d5..faf11e2a3 100644 --- a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs +++ b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -57,7 +57,7 @@ namespace NzbDrone.Core.MediaFiles _logger.Debug("Setting last accessed: {0}", path); _diskProvider.FolderSetLastWriteTime(destination, DateTime.UtcNow); - foreach (var file in _diskProvider.GetFiles(destination, SearchOption.AllDirectories)) + foreach (var file in _diskProvider.GetFiles(destination, true)) { SetLastWriteTime(file, DateTime.UtcNow); } @@ -146,7 +146,7 @@ namespace NzbDrone.Core.MediaFiles _diskProvider.DeleteFolder(folder, true); } - foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.TopDirectoryOnly)) + foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, false)) { _diskProvider.DeleteFile(file); } @@ -172,7 +172,7 @@ namespace NzbDrone.Core.MediaFiles _logger.Info("Removing items older than {0} days from the recycling bin", cleanupDays); - foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.AllDirectories)) + foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, true)) { if (_diskProvider.FileGetLastWrite(file).AddDays(cleanupDays) > DateTime.UtcNow) { diff --git a/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/MacOsVersionAdapterFixture.cs b/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/MacOsVersionAdapterFixture.cs index b650422cd..b4df1027a 100644 --- a/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/MacOsVersionAdapterFixture.cs +++ b/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/MacOsVersionAdapterFixture.cs @@ -1,4 +1,4 @@ -using System.IO; +using System.IO; using FluentAssertions; using Moq; using NUnit.Framework; @@ -25,7 +25,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters .Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true); Mocker.GetMock() - .Setup(c => c.GetFiles("/System/Library/CoreServices/", SearchOption.TopDirectoryOnly)) + .Setup(c => c.GetFiles("/System/Library/CoreServices/", false)) .Returns(new[] { plistPath }); Mocker.GetMock() @@ -49,7 +49,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters .Setup(c => c.FolderExists("/System/Library/CoreServices/")).Returns(true); Mocker.GetMock() - .Setup(c => c.GetFiles("/System/Library/CoreServices/", SearchOption.TopDirectoryOnly)) + .Setup(c => c.GetFiles("/System/Library/CoreServices/", false)) .Returns(new[] { plistPath }); Mocker.GetMock() @@ -69,7 +69,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters Subject.Read().Should().BeNull(); Mocker.GetMock() - .Verify(c => c.GetFiles(It.IsAny(), SearchOption.TopDirectoryOnly), Times.Never()); + .Verify(c => c.GetFiles(It.IsAny(), false), Times.Never()); } } } diff --git a/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapterFixture.cs b/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapterFixture.cs index b257e5713..496f4eefa 100644 --- a/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapterFixture.cs +++ b/src/NzbDrone.Mono.Test/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapterFixture.cs @@ -1,4 +1,4 @@ -using System; +using System; using System.IO; using FluentAssertions; using Moq; @@ -29,25 +29,25 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters } [Test] - public void should_return_null_if_etc_doestn_exist() + public void should_return_null_if_etc_doesnt_exist() { Mocker.GetMock().Setup(c => c.FolderExists("/etc/")).Returns(false); Subject.Read().Should().BeNull(); Mocker.GetMock() - .Verify(c => c.GetFiles(It.IsAny(), SearchOption.TopDirectoryOnly), Times.Never()); + .Verify(c => c.GetFiles(It.IsAny(), false), Times.Never()); Subject.Read().Should().BeNull(); } [Test] - public void should_return_null_if_release_file_doestn_exist() + public void should_return_null_if_release_file_doesnt_exist() { Mocker.GetMock().Setup(c => c.FolderExists("/etc/")).Returns(true); Subject.Read().Should().BeNull(); Mocker.GetMock() - .Setup(c => c.GetFiles(It.IsAny(), SearchOption.TopDirectoryOnly)).Returns(Array.Empty()); + .Setup(c => c.GetFiles(It.IsAny(), false)).Returns(Array.Empty()); Subject.Read().Should().BeNull(); } @@ -59,7 +59,7 @@ namespace NzbDrone.Mono.Test.EnvironmentInfo.VersionAdapters Subject.Read().Should().BeNull(); Mocker.GetMock() - .Setup(c => c.GetFiles(It.IsAny(), SearchOption.TopDirectoryOnly)).Returns(new[] + .Setup(c => c.GetFiles(It.IsAny(), false)).Returns(new[] { "/etc/lsb-release", "/etc/os-release" diff --git a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/IssueFileVersionAdapter.cs b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/IssueFileVersionAdapter.cs index 2965f5a1a..4113c3993 100644 --- a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/IssueFileVersionAdapter.cs +++ b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/IssueFileVersionAdapter.cs @@ -1,4 +1,3 @@ -using System.IO; using System.Linq; using NzbDrone.Common.Disk; using NzbDrone.Common.EnvironmentInfo; @@ -21,7 +20,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters return null; } - var issueFile = _diskProvider.GetFiles("/etc/", SearchOption.TopDirectoryOnly).SingleOrDefault(c => c.EndsWith("/issue")); + var issueFile = _diskProvider.GetFiles("/etc/", false).SingleOrDefault(c => c.EndsWith("/issue")); if (issueFile == null) { diff --git a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/MacOsVersionAdapter.cs b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/MacOsVersionAdapter.cs index 59f743da2..1171334b5 100644 --- a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/MacOsVersionAdapter.cs +++ b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/MacOsVersionAdapter.cs @@ -1,4 +1,3 @@ -using System.IO; using System.Linq; using System.Text.RegularExpressions; using NLog; @@ -33,7 +32,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters return null; } - var allFiles = _diskProvider.GetFiles(PLIST_DIR, SearchOption.TopDirectoryOnly); + var allFiles = _diskProvider.GetFiles(PLIST_DIR, false); var versionFile = allFiles.SingleOrDefault(c => c.EndsWith("/SystemVersion.plist") || diff --git a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapter.cs b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapter.cs index 9347176b2..77c4b9edc 100644 --- a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapter.cs +++ b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/ReleaseFileVersionAdapter.cs @@ -1,4 +1,3 @@ -using System.IO; using System.Linq; using System.Text.RegularExpressions; using NzbDrone.Common.Disk; @@ -22,7 +21,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters return null; } - var releaseFiles = _diskProvider.GetFiles("/etc/", SearchOption.TopDirectoryOnly).Where(c => c.EndsWith("release")).ToList(); + var releaseFiles = _diskProvider.GetFiles("/etc/", false).Where(c => c.EndsWith("release")).ToList(); var name = "Linux"; var fullName = ""; diff --git a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/SynologyVersionAdapter.cs b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/SynologyVersionAdapter.cs index 994867527..b27c0d7e4 100644 --- a/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/SynologyVersionAdapter.cs +++ b/src/NzbDrone.Mono/EnvironmentInfo/VersionAdapters/SynologyVersionAdapter.cs @@ -1,4 +1,3 @@ -using System.IO; using System.Linq; using System.Text.RegularExpressions; using NzbDrone.Common.Disk; @@ -24,7 +23,7 @@ namespace NzbDrone.Mono.EnvironmentInfo.VersionAdapters return null; } - var versionFile = _diskProvider.GetFiles("/etc.defaults/", SearchOption.TopDirectoryOnly).SingleOrDefault(c => c.EndsWith("VERSION")); + var versionFile = _diskProvider.GetFiles("/etc.defaults/", false).SingleOrDefault(c => c.EndsWith("VERSION")); if (versionFile == null) { diff --git a/src/Sonarr.Api.V3/Logs/LogFileController.cs b/src/Sonarr.Api.V3/Logs/LogFileController.cs index eb3b78ece..0e796a7e0 100644 --- a/src/Sonarr.Api.V3/Logs/LogFileController.cs +++ b/src/Sonarr.Api.V3/Logs/LogFileController.cs @@ -25,7 +25,7 @@ namespace Sonarr.Api.V3.Logs protected override IEnumerable GetLogFiles() { - return _diskProvider.GetFiles(_appFolderInfo.GetLogFolder(), SearchOption.TopDirectoryOnly); + return _diskProvider.GetFiles(_appFolderInfo.GetLogFolder(), false); } protected override string GetLogFilePath(string filename) diff --git a/src/Sonarr.Api.V3/Logs/UpdateLogFileController.cs b/src/Sonarr.Api.V3/Logs/UpdateLogFileController.cs index 4f6e8a928..386eec0e9 100644 --- a/src/Sonarr.Api.V3/Logs/UpdateLogFileController.cs +++ b/src/Sonarr.Api.V3/Logs/UpdateLogFileController.cs @@ -32,7 +32,7 @@ namespace Sonarr.Api.V3.Logs return Enumerable.Empty(); } - return _diskProvider.GetFiles(_appFolderInfo.GetUpdateLogFolder(), SearchOption.TopDirectoryOnly) + return _diskProvider.GetFiles(_appFolderInfo.GetUpdateLogFolder(), false) .Where(f => Regex.IsMatch(Path.GetFileName(f), LOGFILE_ROUTE.TrimStart('/'), RegexOptions.IgnoreCase)) .ToList(); }