From b3abcb609694f4f14d41dbb9dc07793b3ad0ba4a Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Sat, 15 Oct 2011 11:54:39 -0700 Subject: [PATCH] RootDirProvider.GetMostFreeRootDir() will calculate the find the RootDir with the most free space and return its path. --- NzbDrone.Core/Providers/RootDirProvider.cs | 20 ++++++++++++++++++++ NzbDrone.Core/Repository/RootDir.cs | 3 +++ 2 files changed, 23 insertions(+) diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs index a7111e353..d88c728c8 100644 --- a/NzbDrone.Core/Providers/RootDirProvider.cs +++ b/NzbDrone.Core/Providers/RootDirProvider.cs @@ -83,6 +83,26 @@ namespace NzbDrone.Core.Providers return results; } + public virtual string GetMostFreeRootDir() + { + ulong maxSize = 0; + var maxPath = String.Empty; + + var rootDirs = GetAll(); + + foreach (var rootDir in rootDirs) + { + rootDir.FreeSpace = new DirectoryInfo(rootDir.Path).FreeDiskSpace(); + if (rootDir.FreeSpace > maxSize) + { + maxPath = rootDir.Path; + maxSize = rootDir.FreeSpace; + } + } + + return maxPath; + } + #endregion } } \ No newline at end of file diff --git a/NzbDrone.Core/Repository/RootDir.cs b/NzbDrone.Core/Repository/RootDir.cs index bb93f636c..28f0d1c00 100644 --- a/NzbDrone.Core/Repository/RootDir.cs +++ b/NzbDrone.Core/Repository/RootDir.cs @@ -9,5 +9,8 @@ namespace NzbDrone.Core.Repository public virtual int Id { get; set; } public string Path { get; set; } + + [ResultColumn] + public ulong FreeSpace { get; set; } } } \ No newline at end of file