diff --git a/src/NzbDrone.Common/DiskProvider.cs b/src/NzbDrone.Common/DiskProvider.cs index a3d9e0255..c1a72b6d1 100644 --- a/src/NzbDrone.Common/DiskProvider.cs +++ b/src/NzbDrone.Common/DiskProvider.cs @@ -303,25 +303,23 @@ public void InheritFolderPermissions(string filename) { var drives = DriveInfo.GetDrives(); - foreach (var drive in drives) + try { - try - { - if (drive.IsReady && path.StartsWith(drive.Name, StringComparison.CurrentCultureIgnoreCase)) - { - return drive.AvailableFreeSpace; - } - } - catch (InvalidOperationException e) - { - Logger.ErrorException("Couldn't get free space for " + path, e); - } + return + drives.Where(drive => + drive.IsReady && path.StartsWith(drive.Name, StringComparison.CurrentCultureIgnoreCase)) + .OrderByDescending(drive => drive.Name.Length) + .First() + .AvailableFreeSpace; + } + catch (InvalidOperationException e) + { + Logger.ErrorException("Couldn't get free space for " + path, e); } return null; } - return DriveFreeSpaceEx(root); }