New: Opt-in to delete empty series/season folders

This commit is contained in:
Mark McDowall 2018-02-11 09:01:41 -08:00
parent a9c54a1f01
commit 9e7f0c859f
6 changed files with 62 additions and 12 deletions

View File

@ -1,4 +1,4 @@
using NzbDrone.Api.REST;
using NzbDrone.Api.REST;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles;
@ -10,6 +10,7 @@ namespace NzbDrone.Api.Config
public string RecycleBin { get; set; }
public bool AutoDownloadPropers { get; set; }
public bool CreateEmptySeriesFolders { get; set; }
public bool DeleteEmptyFolders { get; set; }
public FileDateType FileDate { get; set; }
public bool SetPermissionsLinux { get; set; }
@ -35,6 +36,7 @@ namespace NzbDrone.Api.Config
RecycleBin = model.RecycleBin,
AutoDownloadPropers = model.AutoDownloadPropers,
CreateEmptySeriesFolders = model.CreateEmptySeriesFolders,
DeleteEmptyFolders = model.DeleteEmptyFolders,
FileDate = model.FileDate,
SetPermissionsLinux = model.SetPermissionsLinux,

View File

@ -1,4 +1,4 @@
using System;
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
@ -161,6 +161,13 @@ namespace NzbDrone.Core.Configuration
set { SetValue("CreateEmptySeriesFolders", value); }
}
public bool DeleteEmptyFolders
{
get { return GetValueBoolean("DeleteEmptyFolders", false); }
set { SetValue("DeleteEmptyFolders", value); }
}
public FileDateType FileDate
{
get { return GetValueEnum("FileDate", FileDateType.None); }

View File

@ -1,4 +1,4 @@
using System.Collections.Generic;
using System.Collections.Generic;
using NzbDrone.Core.MediaFiles;
using NzbDrone.Common.Http.Proxy;
@ -28,6 +28,7 @@ namespace NzbDrone.Core.Configuration
string RecycleBin { get; set; }
bool AutoDownloadPropers { get; set; }
bool CreateEmptySeriesFolders { get; set; }
bool DeleteEmptyFolders { get; set; }
FileDateType FileDate { get; set; }
bool SkipFreeSpaceCheckWhenImporting { get; set; }
bool CopyUsingHardlinks { get; set; }

View File

@ -191,10 +191,16 @@ namespace NzbDrone.Core.MediaFiles
private void RemoveEmptySeriesFolder(string path)
{
if (_diskProvider.GetFiles(path, SearchOption.AllDirectories).Empty() &&
!_configService.CreateEmptySeriesFolders)
if (_configService.DeleteEmptyFolders)
{
_diskProvider.DeleteFolder(path, true);
if (_diskProvider.GetFiles(path, SearchOption.AllDirectories).Empty())
{
_diskProvider.DeleteFolder(path, true);
}
else
{
_diskProvider.RemoveEmptySubfolders(path);
}
}
}

View File

@ -117,13 +117,24 @@ namespace NzbDrone.Core.MediaFiles
[EventHandleOrder(EventHandleOrder.Last)]
public void Handle(EpisodeFileDeletedEvent message)
{
var series = message.EpisodeFile.Series.Value;
var path = series.Path;
if (_diskProvider.GetFiles(path, SearchOption.AllDirectories).Empty() &&
!_configService.CreateEmptySeriesFolders)
if (message.Reason == DeleteMediaFileReason.Upgrade)
{
_diskProvider.DeleteFolder(path, true);
return;
}
if (_configService.DeleteEmptyFolders)
{
var series = message.EpisodeFile.Series.Value;
var seasonFolder = message.EpisodeFile.Path.GetParentPath();
if (_diskProvider.GetFiles(series.Path, SearchOption.AllDirectories).Empty())
{
_diskProvider.DeleteFolder(series.Path, true);
}
else if (_diskProvider.GetFiles(seasonFolder, SearchOption.AllDirectories).Empty())
{
_diskProvider.RemoveEmptySubfolders(seasonFolder);
}
}
}
}

View File

@ -23,6 +23,29 @@
</div>
</div>
</div>
<div class="form-group">
<label class="col-sm-3 control-label">Delete empty folders</label>
<div class="col-sm-9">
<div class="input-group">
<label class="checkbox toggle well">
<input type="checkbox" name="deleteEmptyFolders"/>
<p>
<span>Yes</span>
<span>No</span>
</p>
<div class="btn btn-primary slide-button"/>
</label>
<span class="help-inline-checkbox">
<i class="icon-sonarr-form-info" title="Delete empty series and season folders during disk scan and when episode files are deleted"/>
</span>
</div>
</div>
</div>
</fieldset>
<fieldset>