Recycle bin file cleanup
Fixed: Recycle bin will clean up files older than 7 days and remove empty folders left behind
This commit is contained in:
parent
08641a6694
commit
d273a72cb3
|
@ -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()
|
||||
{
|
||||
|
|
|
@ -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.");
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue