diff --git a/NzbDrone.Common/DiskProvider.cs b/NzbDrone.Common/DiskProvider.cs index ad4f08580..cb15a672f 100644 --- a/NzbDrone.Common/DiskProvider.cs +++ b/NzbDrone.Common/DiskProvider.cs @@ -294,13 +294,14 @@ namespace NzbDrone.Common { Ensure.That(() => path).IsValidPath(); - if (!FolderExists(path)) - throw new DirectoryNotFoundException(path); + var root = GetPathRoot(path); + if (!FolderExists(root)) + throw new DirectoryNotFoundException(root); if (OsInfo.IsLinux) { - var driveInfo = DriveInfo.GetDrives().SingleOrDefault(c => c.IsReady && c.Name.Equals(Path.GetPathRoot(path), StringComparison.CurrentCultureIgnoreCase)); + var driveInfo = DriveInfo.GetDrives().SingleOrDefault(c => c.IsReady && c.Name.Equals(root, StringComparison.CurrentCultureIgnoreCase)); if (driveInfo == null) { @@ -310,7 +311,7 @@ namespace NzbDrone.Common return driveInfo.AvailableFreeSpace; } - return DriveFreeSpaceEx(path); + return DriveFreeSpaceEx(root); } private static long DriveFreeSpaceEx(string folderName) diff --git a/NzbDrone.Core.Test/MediaFileTests/EpisodeImportTests/FreeSpaceSpecificationFixture.cs b/NzbDrone.Core.Test/MediaFileTests/EpisodeImportTests/FreeSpaceSpecificationFixture.cs index 1f033a769..bda744ca5 100644 --- a/NzbDrone.Core.Test/MediaFileTests/EpisodeImportTests/FreeSpaceSpecificationFixture.cs +++ b/NzbDrone.Core.Test/MediaFileTests/EpisodeImportTests/FreeSpaceSpecificationFixture.cs @@ -54,7 +54,6 @@ namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests } [Test] - [Ignore] public void should_reject_when_there_isnt_enough_disk_space() { GivenFileSize(100.Megabytes()); @@ -65,7 +64,6 @@ namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests } [Test] - [Ignore] public void should_reject_when_there_isnt_enough_space_for_file_plus_100mb_padding() { GivenFileSize(100.Megabytes()); @@ -76,7 +74,6 @@ namespace NzbDrone.Core.Test.MediaFileTests.EpisodeImportTests } [Test] - [Ignore] public void should_accept_when_there_is_enough_disk_space() { GivenFileSize(100.Megabytes()); diff --git a/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs b/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs index 618b57a45..9ae177c51 100644 --- a/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs +++ b/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs @@ -31,5 +31,12 @@ namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests { Assert.Throws(() => Subject.GetAvilableSpace(@"Z:\NOT_A_REAL_PATH\DOES_NOT_EXIST".AsOsAgnostic())); } + + [Test] + public void should_be_able_to_get_space_on_folder_that_doesnt_exist() + { + var result = Subject.GetAvilableSpace(@"C:\I_DO_NOT_EXIST".AsOsAgnostic()); + result.Should().BeGreaterThan(0); + } } } diff --git a/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/FreeSpaceSpecification.cs b/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/FreeSpaceSpecification.cs index a25413d6e..4d017775b 100644 --- a/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/FreeSpaceSpecification.cs +++ b/NzbDrone.Core/MediaFiles/EpisodeImport/Specifications/FreeSpaceSpecification.cs @@ -9,13 +9,11 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications { public class FreeSpaceSpecification : IImportDecisionEngineSpecification { - private readonly IBuildFileNames _buildFileNames; private readonly IDiskProvider _diskProvider; private readonly Logger _logger; - public FreeSpaceSpecification(IBuildFileNames buildFileNames, IDiskProvider diskProvider, Logger logger) + public FreeSpaceSpecification(IDiskProvider diskProvider, Logger logger) { - _buildFileNames = buildFileNames; _diskProvider = diskProvider; _logger = logger; } @@ -23,14 +21,8 @@ namespace NzbDrone.Core.MediaFiles.EpisodeImport.Specifications public string RejectionReason { get { return "Not enough free space"; } } public bool IsSatisfiedBy(LocalEpisode localEpisode) - { - //TODO: fix issues with this, seems to be completely broken... - return true; - - var newFileName = Path.GetFileNameWithoutExtension(localEpisode.Path); - var destinationFilename = _buildFileNames.BuildFilePath(localEpisode.Series, localEpisode.SeasonNumber, newFileName, Path.GetExtension(localEpisode.Path)); - - var freeSpace = _diskProvider.GetAvilableSpace(destinationFilename); + { + var freeSpace = _diskProvider.GetAvilableSpace(localEpisode.Series.Path); if (freeSpace < localEpisode.Size + 100.Megabytes()) {