diff --git a/NzbDrone.Core.Test/FluentTest.cs b/NzbDrone.Core.Test/FluentTest.cs
index bed081666..26d88c907 100644
--- a/NzbDrone.Core.Test/FluentTest.cs
+++ b/NzbDrone.Core.Test/FluentTest.cs
@@ -80,13 +80,5 @@ namespace NzbDrone.Core.Test
Console.WriteLine(dateTime.DayOfWeek);
dateTime.ToBestDateString().Should().Be(dateTime.ToShortDateString());
}
-
- [Test]
- public void FreeDiskSpace()
- {
- //Checks to ensure that the free space on the first is greater than 0 (It should be in 99.99999999999999% of cases... I hope)
- var di = new DirectoryInfo(Directory.GetCurrentDirectory());
- di.FreeDiskSpace().Should().BeGreaterThan(0);
- }
}
}
diff --git a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
index 89d425295..1aa915b0d 100644
--- a/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
+++ b/NzbDrone.Core.Test/NzbDrone.Core.Test.csproj
@@ -85,6 +85,7 @@
+
diff --git a/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs b/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs
new file mode 100644
index 000000000..56e4c4934
--- /dev/null
+++ b/NzbDrone.Core.Test/ProviderTests/DiskProviderTests/FreeDiskSpaceTest.cs
@@ -0,0 +1,33 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Linq;
+using System.Text;
+using AutoMoq;
+using FluentAssertions;
+using Moq;
+using NUnit.Framework;
+using NzbDrone.Core.Providers.Core;
+using NzbDrone.Core.Test.Framework;
+
+namespace NzbDrone.Core.Test.ProviderTests.DiskProviderTests
+{
+ [TestFixture]
+ public class FreeDiskSpaceTest : TestBase
+ {
+ [Test]
+ public void FreeDiskSpace()
+ {
+ //Setup
+ var mocker = new AutoMoqer();
+
+ //Act
+ var di = new DirectoryInfo(Directory.GetCurrentDirectory());
+ var result = mocker.Resolve().FreeDiskSpace(di);
+
+ //Asert
+ //Checks to ensure that the free space on the first is greater than 0 (It should be in 99.99999999999999% of cases... I hope)
+ result.Should().BeGreaterThan(0);
+ }
+ }
+}
diff --git a/NzbDrone.Core/Fluent.cs b/NzbDrone.Core/Fluent.cs
index 317acdb43..9d9cabdf6 100644
--- a/NzbDrone.Core/Fluent.cs
+++ b/NzbDrone.Core/Fluent.cs
@@ -8,13 +8,6 @@ namespace NzbDrone.Core
{
public static class Fluent
{
- [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
- [return: MarshalAs(UnmanagedType.Bool)]
- static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
- out ulong lpFreeBytesAvailable,
- out ulong lpTotalNumberOfBytes,
- out ulong lpTotalNumberOfFreeBytes);
-
public static string WithDefault(this string actual, object defaultValue)
{
if (defaultValue == null)
@@ -54,20 +47,9 @@ namespace NzbDrone.Core
return dateTime.ToShortDateString();
}
-
- //TODO: this should be moved to DiskProvider
- public static ulong FreeDiskSpace(this DirectoryInfo directoryInfo)
+ public static string ParentUriString(this Uri uri)
{
- ulong freeBytesAvailable;
- ulong totalNumberOfBytes;
- ulong totalNumberOfFreeBytes;
-
- bool success = GetDiskFreeSpaceEx(directoryInfo.FullName, out freeBytesAvailable, out totalNumberOfBytes,
- out totalNumberOfFreeBytes);
- if (!success)
- throw new System.ComponentModel.Win32Exception();
-
- return freeBytesAvailable;
+ return uri.AbsoluteUri.Remove(uri.AbsoluteUri.Length - String.Join("", uri.Segments).Length);
}
}
}
diff --git a/NzbDrone.Core/Providers/Core/DiskProvider.cs b/NzbDrone.Core/Providers/Core/DiskProvider.cs
index 8c15f0566..4fe32a0f7 100644
--- a/NzbDrone.Core/Providers/Core/DiskProvider.cs
+++ b/NzbDrone.Core/Providers/Core/DiskProvider.cs
@@ -2,6 +2,7 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
+using System.Runtime.InteropServices;
using Ionic.Zip;
using NLog;
@@ -9,6 +10,13 @@ namespace NzbDrone.Core.Providers.Core
{
public class DiskProvider
{
+ [DllImport("kernel32.dll", SetLastError = true, CharSet = CharSet.Auto)]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ static extern bool GetDiskFreeSpaceEx(string lpDirectoryName,
+ out ulong lpFreeBytesAvailable,
+ out ulong lpTotalNumberOfBytes,
+ out ulong lpTotalNumberOfFreeBytes);
+
private static readonly Logger Logger = LogManager.GetCurrentClassLogger();
public virtual bool FolderExists(string path)
@@ -96,5 +104,19 @@ namespace NzbDrone.Core.Providers.Core
fs.SetAccessRuleProtection(false, false);
File.SetAccessControl(filename, fs);
}
+
+ public virtual ulong FreeDiskSpace(DirectoryInfo directoryInfo)
+ {
+ ulong freeBytesAvailable;
+ ulong totalNumberOfBytes;
+ ulong totalNumberOfFreeBytes;
+
+ bool success = GetDiskFreeSpaceEx(directoryInfo.FullName, out freeBytesAvailable, out totalNumberOfBytes,
+ out totalNumberOfFreeBytes);
+ if (!success)
+ throw new System.ComponentModel.Win32Exception();
+
+ return freeBytesAvailable;
+ }
}
}
\ No newline at end of file
diff --git a/NzbDrone.Core/Providers/RootDirProvider.cs b/NzbDrone.Core/Providers/RootDirProvider.cs
index d88c728c8..4c4c804ef 100644
--- a/NzbDrone.Core/Providers/RootDirProvider.cs
+++ b/NzbDrone.Core/Providers/RootDirProvider.cs
@@ -92,7 +92,7 @@ namespace NzbDrone.Core.Providers
foreach (var rootDir in rootDirs)
{
- rootDir.FreeSpace = new DirectoryInfo(rootDir.Path).FreeDiskSpace();
+ rootDir.FreeSpace = _diskProvider.FreeDiskSpace(new DirectoryInfo(rootDir.Path));
if (rootDir.FreeSpace > maxSize)
{
maxPath = rootDir.Path;