From 3dd8e7240ea14e8bc2a36a0f15c5da6263043c1f Mon Sep 17 00:00:00 2001 From: "kay.one" Date: Tue, 5 Jul 2011 00:09:07 -0700 Subject: [PATCH] Added GetDirectorySize to DiskProvider Removed search folder from disk provider --- NzbDrone.Core.Test/Framework/MockLib.cs | 27 +------------------ NzbDrone.Core/Providers/Core/DiskProvider.cs | 10 +++++-- NzbDrone.Core/Providers/DiskScanProvider.cs | 2 +- .../Providers/Jobs/PostDownloadScanJob.cs | 2 +- 4 files changed, 11 insertions(+), 30 deletions(-) diff --git a/NzbDrone.Core.Test/Framework/MockLib.cs b/NzbDrone.Core.Test/Framework/MockLib.cs index a68f47568..9cf224e7f 100644 --- a/NzbDrone.Core.Test/Framework/MockLib.cs +++ b/NzbDrone.Core.Test/Framework/MockLib.cs @@ -39,32 +39,7 @@ namespace NzbDrone.Core.Test.Framework return database; } - public static DiskProvider GetStandardDisk(int seasons, int episodes) - { - var mock = new Mock(); - mock.Setup(c => c.GetDirectories(It.IsAny())).Returns(StandardSeries); - mock.Setup(c => c.FolderExists(It.Is(d => StandardSeries.Contains(d)))).Returns(true); - - - foreach (var series in StandardSeries) - { - var file = new List(); - for (int s = 0; s < seasons; s++) - { - for (int e = 0; e < episodes; e++) - { - file.Add(String.Format("{0}\\Seasons {1}\\myepname.S{1:00}E{2:00}.avi", series, s, e)); - } - } - - string series1 = series; - mock.Setup(c => c.GetFiles(series1, "*.avi", SearchOption.AllDirectories)).Returns(file.ToArray()); - } - - return mock.Object; - } - - public static Series GetFakeSeries(int id, string title) + public static Series GetFakeSeries(int id, string title) { return Builder.CreateNew() .With(c => c.SeriesId = id) diff --git a/NzbDrone.Core/Providers/Core/DiskProvider.cs b/NzbDrone.Core/Providers/Core/DiskProvider.cs index 8e8ae2cb0..3a22a4328 100644 --- a/NzbDrone.Core/Providers/Core/DiskProvider.cs +++ b/NzbDrone.Core/Providers/Core/DiskProvider.cs @@ -1,4 +1,5 @@ using System; +using System.Linq; using System.Collections.Generic; using System.IO; @@ -21,9 +22,14 @@ namespace NzbDrone.Core.Providers.Core return Directory.GetDirectories(path); } - public virtual string[] GetFiles(string path, string pattern, SearchOption searchOption) + public virtual string[] GetFiles(string path, SearchOption searchOption) { - return Directory.GetFiles(path, pattern, searchOption); + return Directory.GetFiles(path, "*.*", searchOption); + } + + public virtual long GetDirectorySize(string path) + { + return GetFiles(path, SearchOption.AllDirectories).Sum(e => new FileInfo(e).Length); } public virtual long GetSize(string path) diff --git a/NzbDrone.Core/Providers/DiskScanProvider.cs b/NzbDrone.Core/Providers/DiskScanProvider.cs index 456d7349e..d3fc5e6c6 100644 --- a/NzbDrone.Core/Providers/DiskScanProvider.cs +++ b/NzbDrone.Core/Providers/DiskScanProvider.cs @@ -196,7 +196,7 @@ namespace NzbDrone.Core.Providers { Logger.Debug("Scanning '{0}' for episodes", path); - var filesOnDisk = _diskProvider.GetFiles(path, "*.*", SearchOption.AllDirectories); + var filesOnDisk = _diskProvider.GetFiles(path, SearchOption.AllDirectories); var mediaFileList = filesOnDisk.Where(c => MediaExtentions.Contains(Path.GetExtension(c).ToLower())).ToList(); diff --git a/NzbDrone.Core/Providers/Jobs/PostDownloadScanJob.cs b/NzbDrone.Core/Providers/Jobs/PostDownloadScanJob.cs index 241fcdb39..b26eab842 100644 --- a/NzbDrone.Core/Providers/Jobs/PostDownloadScanJob.cs +++ b/NzbDrone.Core/Providers/Jobs/PostDownloadScanJob.cs @@ -88,7 +88,7 @@ namespace NzbDrone.Core.Providers.Jobs importedFiles.ForEach(file => _diskScanProvider.MoveEpisodeFile(file)); //Delete the folder only if all files were removed - if (_diskProvider.GetFiles(subfolder, "*.*", SearchOption.AllDirectories).Length == 0) + if (_diskProvider.GetFiles(subfolder, SearchOption.AllDirectories).Length == 0) _diskProvider.DeleteFolder(subfolder, false); } catch (Exception e)