mirror of https://github.com/lidarr/Lidarr
New: Cleanup Recycling Bin folders older than X days (0 to disable)
Co-Authored-By: Mark McDowall <markus101@users.noreply.github.com>
This commit is contained in:
parent
0496e6afc2
commit
699f19b352
|
@ -299,11 +299,27 @@ class MediaManagement extends Component {
|
|||
type={inputTypes.PATH}
|
||||
name="recycleBin"
|
||||
helpText="Track files will go here when deleted instead of being permanently deleted"
|
||||
helpTextWarning="Files in the recycle bin older than a week will be cleaned up automatically"
|
||||
onChange={onInputChange}
|
||||
{...settings.recycleBin}
|
||||
/>
|
||||
</FormGroup>
|
||||
|
||||
<FormGroup
|
||||
advancedSettings={advancedSettings}
|
||||
isAdvanced={true}
|
||||
>
|
||||
<FormLabel>Recycling Bin Cleanup</FormLabel>
|
||||
|
||||
<FormInputGroup
|
||||
type={inputTypes.NUMBER}
|
||||
name="recycleBinCleanupDays"
|
||||
helpText="Set to 0 to disable automatic cleanup"
|
||||
helpTextWarning="Files in the recycle bin older than the selected number of days will be cleaned up automatically"
|
||||
min={0}
|
||||
onChange={onInputChange}
|
||||
{...settings.recycleBinCleanupDays}
|
||||
/>
|
||||
</FormGroup>
|
||||
</FieldSet>
|
||||
|
||||
{
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Lidarr.Api.V1.Config
|
|||
public MediaManagementConfigModule(IConfigService configService, PathExistsValidator pathExistsValidator)
|
||||
: base(configService)
|
||||
{
|
||||
SharedValidator.RuleFor(c => c.RecycleBinCleanupDays).GreaterThanOrEqualTo(0);
|
||||
SharedValidator.RuleFor(c => c.FileChmod).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.FolderChmod).NotEmpty();
|
||||
SharedValidator.RuleFor(c => c.RecycleBin).IsValidPath().SetValidator(pathExistsValidator).When(c => !string.IsNullOrWhiteSpace(c.RecycleBin));
|
||||
|
|
|
@ -9,6 +9,7 @@ namespace Lidarr.Api.V1.Config
|
|||
{
|
||||
public bool AutoUnmonitorPreviouslyDownloadedTracks { get; set; }
|
||||
public string RecycleBin { get; set; }
|
||||
public int RecycleBinCleanupDays { get; set; }
|
||||
public ProperDownloadTypes DownloadPropersAndRepacks { get; set; }
|
||||
public bool CreateEmptyArtistFolders { get; set; }
|
||||
public bool DeleteEmptyFolders { get; set; }
|
||||
|
@ -36,6 +37,7 @@ namespace Lidarr.Api.V1.Config
|
|||
{
|
||||
AutoUnmonitorPreviouslyDownloadedTracks = model.AutoUnmonitorPreviouslyDownloadedTracks,
|
||||
RecycleBin = model.RecycleBin,
|
||||
RecycleBinCleanupDays = model.RecycleBinCleanupDays,
|
||||
DownloadPropersAndRepacks = model.DownloadPropersAndRepacks,
|
||||
CreateEmptyArtistFolders = model.CreateEmptyArtistFolders,
|
||||
DeleteEmptyFolders = model.DeleteEmptyFolders,
|
||||
|
|
|
@ -37,6 +37,7 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
|
|||
public void Setup()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(s => s.RecycleBin).Returns(RecycleBin);
|
||||
Mocker.GetMock<IConfigService>().SetupGet(s => s.RecycleBinCleanupDays).Returns(7);
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Setup(s => s.GetDirectories(RecycleBin))
|
||||
.Returns(new [] { @"C:\Test\RecycleBin\Folder1", @"C:\Test\RecycleBin\Folder2", @"C:\Test\RecycleBin\Folder3" });
|
||||
|
@ -56,12 +57,13 @@ namespace NzbDrone.Core.Test.ProviderTests.RecycleBinProviderTests
|
|||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_all_expired_folders()
|
||||
{
|
||||
WithExpired();
|
||||
public void should_return_if_recycleBinCleanupDays_is_zero()
|
||||
{
|
||||
Mocker.GetMock<IConfigService>().SetupGet(s => s.RecycleBinCleanupDays).Returns(0);
|
||||
|
||||
Mocker.Resolve<RecycleBinProvider>().Cleanup();
|
||||
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.DeleteFolder(It.IsAny<string>(), true), Times.Exactly(3));
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetDirectories(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
|
|
|
@ -92,6 +92,12 @@ namespace NzbDrone.Core.Configuration
|
|||
set { SetValue("RecycleBin", value); }
|
||||
}
|
||||
|
||||
public int RecycleBinCleanupDays
|
||||
{
|
||||
get { return GetValueInt("RecycleBinCleanupDays", 7); }
|
||||
set { SetValue("RecycleBinCleanupDays", value); }
|
||||
}
|
||||
|
||||
public int RssSyncInterval
|
||||
{
|
||||
get { return GetValueInt("RssSyncInterval", 15); }
|
||||
|
|
|
@ -25,6 +25,7 @@ namespace NzbDrone.Core.Configuration
|
|||
//Media Management
|
||||
bool AutoUnmonitorPreviouslyDownloadedTracks { get; set; }
|
||||
string RecycleBin { get; set; }
|
||||
int RecycleBinCleanupDays { get; set; }
|
||||
ProperDownloadTypes DownloadPropersAndRepacks { get; set; }
|
||||
bool CreateEmptyArtistFolders { get; set; }
|
||||
bool DeleteEmptyFolders { get; set; }
|
||||
|
|
|
@ -157,7 +157,15 @@ namespace NzbDrone.Core.MediaFiles
|
|||
return;
|
||||
}
|
||||
|
||||
_logger.Info("Removing items older than 7 days from the recycling bin");
|
||||
var cleanupDays = _configService.RecycleBinCleanupDays;
|
||||
|
||||
if (cleanupDays == 0)
|
||||
{
|
||||
_logger.Info("Automatic cleanup of Recycle Bin is disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
_logger.Info("Removing items older than {0} days from the recycling bin", cleanupDays);
|
||||
|
||||
foreach (var folder in _diskProvider.GetDirectories(_configService.RecycleBin))
|
||||
{
|
||||
|
@ -172,7 +180,7 @@ namespace NzbDrone.Core.MediaFiles
|
|||
|
||||
foreach (var file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.TopDirectoryOnly))
|
||||
{
|
||||
if (_diskProvider.FileGetLastWrite(file).AddDays(7) > DateTime.UtcNow)
|
||||
if (_diskProvider.FileGetLastWrite(file).AddDays(cleanupDays) > DateTime.UtcNow)
|
||||
{
|
||||
_logger.Debug("File hasn't expired yet, skipping: {0}", file);
|
||||
continue;
|
||||
|
|
Loading…
Reference in New Issue