Fixed: Recycle bin will clean up files older than 7 days and remove empty folders left behind

Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
pull/6/head
Qstick 5 years ago
parent 0ba1bf3eb2
commit 7717b73fdd

@ -42,7 +42,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" });
}

@ -167,18 +167,7 @@ namespace NzbDrone.Core.MediaFiles
_logger.Info("Removing items older than {0} days from the recycling bin", cleanupDays);
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(cleanupDays) > DateTime.UtcNow)
{
@ -189,6 +178,8 @@ namespace NzbDrone.Core.MediaFiles
_diskProvider.DeleteFile(file);
}
_diskProvider.RemoveEmptySubfolders(_configService.RecycleBin);
_logger.Debug("Recycling Bin has been cleaned up.");
}

Loading…
Cancel
Save