mirror of
https://github.com/Sonarr/Sonarr.git
synced 2024-12-14 11:23:42 +02:00
New: Cleanup Recycling Bin folders older than X days (0 to disable)
This commit is contained in:
parent
d72b16531b
commit
8196f6b9db
@ -316,11 +316,27 @@ class MediaManagement extends Component {
|
||||
type={inputTypes.PATH}
|
||||
name="recycleBin"
|
||||
helpText="Episode 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>
|
||||
|
||||
{
|
||||
|
@ -37,6 +37,7 @@ private void WithNonExpired()
|
||||
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" });
|
||||
@ -55,6 +56,16 @@ public void should_return_if_recycleBin_not_configured()
|
||||
Mocker.GetMock<IDiskProvider>().Verify(v => v.GetDirectories(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
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.GetDirectories(It.IsAny<string>()), Times.Never());
|
||||
}
|
||||
|
||||
[Test]
|
||||
public void should_delete_all_expired_files()
|
||||
{
|
||||
|
@ -94,6 +94,12 @@ public string RecycleBin
|
||||
set { SetValue("RecycleBin", value); }
|
||||
}
|
||||
|
||||
public int RecycleBinCleanupDays
|
||||
{
|
||||
get { return GetValueInt("RecycleBinCleanupDays", 7); }
|
||||
set { SetValue("RecycleBinCleanupDays", value); }
|
||||
}
|
||||
|
||||
public int RssSyncInterval
|
||||
{
|
||||
get { return GetValueInt("RssSyncInterval", 15); }
|
||||
|
@ -27,6 +27,7 @@ public interface IConfigService
|
||||
//Media Management
|
||||
bool AutoUnmonitorPreviouslyDownloadedEpisodes { get; set; }
|
||||
string RecycleBin { get; set; }
|
||||
int RecycleBinCleanupDays { get; set; }
|
||||
ProperDownloadTypes DownloadPropersAndRepacks { get; set; }
|
||||
bool CreateEmptySeriesFolders { get; set; }
|
||||
bool DeleteEmptyFolders { get; set; }
|
||||
@ -39,7 +40,6 @@ public interface IConfigService
|
||||
RescanAfterRefreshType RescanAfterRefresh { get; set; }
|
||||
EpisodeTitleRequiredType EpisodeTitleRequired { get; set; }
|
||||
|
||||
|
||||
//Permissions (Media Management)
|
||||
bool SetPermissionsLinux { get; set; }
|
||||
string FileChmod { get; set; }
|
||||
|
@ -157,11 +157,19 @@ public void Cleanup()
|
||||
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 file in _diskProvider.GetFiles(_configService.RecycleBin, SearchOption.AllDirectories))
|
||||
{
|
||||
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;
|
||||
|
@ -9,6 +9,7 @@ public class MediaManagementConfigModule : SonarrConfigModule<MediaManagementCon
|
||||
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));
|
||||
|
@ -10,6 +10,7 @@ public class MediaManagementConfigResource : RestResource
|
||||
{
|
||||
public bool AutoUnmonitorPreviouslyDownloadedEpisodes { get; set; }
|
||||
public string RecycleBin { get; set; }
|
||||
public int RecycleBinCleanupDays { get; set; }
|
||||
public ProperDownloadTypes DownloadPropersAndRepacks { get; set; }
|
||||
public bool CreateEmptySeriesFolders { get; set; }
|
||||
public bool DeleteEmptyFolders { get; set; }
|
||||
@ -38,6 +39,7 @@ public static MediaManagementConfigResource ToResource(IConfigService model)
|
||||
{
|
||||
AutoUnmonitorPreviouslyDownloadedEpisodes = model.AutoUnmonitorPreviouslyDownloadedEpisodes,
|
||||
RecycleBin = model.RecycleBin,
|
||||
RecycleBinCleanupDays = model.RecycleBinCleanupDays,
|
||||
DownloadPropersAndRepacks = model.DownloadPropersAndRepacks,
|
||||
CreateEmptySeriesFolders = model.CreateEmptySeriesFolders,
|
||||
DeleteEmptyFolders = model.DeleteEmptyFolders,
|
||||
|
Loading…
Reference in New Issue
Block a user