1
0
Fork 0
mirror of https://github.com/Radarr/Radarr synced 2024-12-26 09:49:00 +00:00

FreeSpace check now uses the root of the drive\share as the check

This commit is contained in:
Mark McDowall 2013-08-08 18:40:24 -07:00
parent c8d43accfb
commit 470182e397
4 changed files with 15 additions and 18 deletions

View file

@ -294,13 +294,14 @@ public long GetAvilableSpace(string path)
{
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 @@ public long GetAvilableSpace(string path)
return driveInfo.AvailableFreeSpace;
}
return DriveFreeSpaceEx(path);
return DriveFreeSpaceEx(root);
}
private static long DriveFreeSpaceEx(string folderName)

View file

@ -54,7 +54,6 @@ private void GivenFreeSpace(long size)
}
[Test]
[Ignore]
public void should_reject_when_there_isnt_enough_disk_space()
{
GivenFileSize(100.Megabytes());
@ -65,7 +64,6 @@ public void should_reject_when_there_isnt_enough_disk_space()
}
[Test]
[Ignore]
public void should_reject_when_there_isnt_enough_space_for_file_plus_100mb_padding()
{
GivenFileSize(100.Megabytes());
@ -76,7 +74,6 @@ public void should_reject_when_there_isnt_enough_space_for_file_plus_100mb_paddi
}
[Test]
[Ignore]
public void should_accept_when_there_is_enough_disk_space()
{
GivenFileSize(100.Megabytes());

View file

@ -31,5 +31,12 @@ public void should_throw_if_drive_doesnt_exist()
{
Assert.Throws<DirectoryNotFoundException>(() => 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);
}
}
}

View file

@ -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;
}
@ -24,13 +22,7 @@ public FreeSpaceSpecification(IBuildFileNames buildFileNames, IDiskProvider disk
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())
{