From 9fcd422f296ced72d6f1c40a3cce2397440f4513 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Tue, 12 Nov 2013 22:38:37 -0800 Subject: [PATCH] Fixed: Total free space on Linux --- src/NzbDrone.Common/DiskProvider.cs | 41 +++++++++++++---------------- 1 file changed, 18 insertions(+), 23 deletions(-) diff --git a/src/NzbDrone.Common/DiskProvider.cs b/src/NzbDrone.Common/DiskProvider.cs index c1a72b6d1..cd62de149 100644 --- a/src/NzbDrone.Common/DiskProvider.cs +++ b/src/NzbDrone.Common/DiskProvider.cs @@ -301,16 +301,9 @@ namespace NzbDrone.Common if (OsInfo.IsLinux) { - var drives = DriveInfo.GetDrives(); - try { - return - drives.Where(drive => - drive.IsReady && path.StartsWith(drive.Name, StringComparison.CurrentCultureIgnoreCase)) - .OrderByDescending(drive => drive.Name.Length) - .First() - .AvailableFreeSpace; + return GetDriveInfoLinux(path).AvailableFreeSpace; } catch (InvalidOperationException e) { @@ -469,27 +462,18 @@ namespace NzbDrone.Common if (OsInfo.IsLinux) { - var drives = DriveInfo.GetDrives(); - - foreach (var drive in drives) + try { - try - { - if (drive.IsReady && path.StartsWith(drive.Name, StringComparison.CurrentCultureIgnoreCase)) - { - return drive.TotalSize; - } - } - catch (InvalidOperationException e) - { - Logger.ErrorException("Couldn't get total space for " + path, e); - } + return GetDriveInfoLinux(path).TotalFreeSpace; + } + catch (InvalidOperationException e) + { + Logger.ErrorException("Couldn't get total space for " + path, e); } return null; } - return DriveTotalSizeEx(root); } @@ -552,5 +536,16 @@ namespace NzbDrone.Common return 0; } + + private DriveInfo GetDriveInfoLinux(string path) + { + var drives = DriveInfo.GetDrives(); + + return + drives.Where(drive => + drive.IsReady && path.StartsWith(drive.Name, StringComparison.CurrentCultureIgnoreCase)) + .OrderByDescending(drive => drive.Name.Length) + .First(); + } } } \ No newline at end of file