diff --git a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs index 4080b6d05..e38908474 100644 --- a/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs +++ b/src/NzbDrone.Core.Test/ProviderTests/RecycleBinProviderTests/CleanupFixture.cs @@ -41,7 +41,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin)) .Returns(new [] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" }); - Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.TopDirectoryOnly)) + Mocker.GetMock<IDiskProvider>().Setup(s => s.GetFiles(RecycleBin, SearchOption.AllDirectories)) .Returns(new [] { @"C:\Test\RecycleBin\File1.avi", @"C:\Test\RecycleBin\File2.mkv" }); } @@ -55,15 +55,6 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests Mocker.GetMock<IDiskProvider>().Verify(v => v.GetDirectories(It.IsAny<string>()), Times.Never()); } - [Test] - public void should_delete_all_expired_folders() - { - WithExpired(); - Mocker.Resolve<RecycleBinProvider>().Cleanup(); - - Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Exactly(3)); - } - [Test] public void should_delete_all_expired_files() { diff --git a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs index 9cac1ca35..85c628ad1 100644 --- a/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs +++ b/src/NzbDrone.Core/MediaFiles/RecycleBinProvider.cs @@ -159,18 +159,7 @@ namespace NzbDrone.Core.MediaFiles _logger.Info("Removing items older than 7 days from the recycling bin"); - foreach (var folder in _diskProvider.GetDirectories(_configService.RecycleBin)) - { - if (_diskProvider.FolderGetLastWrite(folder).AddDays(7) > DateTime.UtcNow) - { - _logger.Debug("Folder hasn't expired yet, skipping: {0}", folder); - continue; - } - - _diskProvider.DeleteFolder(folder, true); - } - - foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.TopDirectoryOnly)) + foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.AllDirectories)) { if (_diskProvider.FileGetLastWrite(file).AddDays(7) > DateTime.UtcNow) { @@ -181,6 +170,8 @@ namespace NzbDrone.Core.MediaFiles _diskProvider.DeleteFile(file); } + _diskProvider.RemoveEmptySubfolders(_configService.RecycleBin); + _logger.Debug("Recycling Bin has been cleaned up."); }