Fixed: Deleting empty episode folders on upgrade

Fixed #3883
This commit is contained in:
Mark McDowall 2020-07-26 12:18:46 -07:00
parent 57335c6d3a
commit ac75a31641
1 changed files with 14 additions and 10 deletions

View File

@ -117,23 +117,27 @@ namespace NzbDrone.Core.MediaFiles
[EventHandleOrder(EventHandleOrder.Last)]
public void Handle(EpisodeFileDeletedEvent message)
{
if (message.Reason == DeleteMediaFileReason.Upgrade)
{
return;
}
if (_configService.DeleteEmptyFolders)
{
var series = message.EpisodeFile.Series.Value;
var seasonFolder = message.EpisodeFile.Path.GetParentPath();
var seriesPath = series.Path;
var folder = message.EpisodeFile.Path.GetParentPath();
if (_diskProvider.GetFiles(series.Path, SearchOption.AllDirectories).Empty())
while (seriesPath.IsParentPath(folder))
{
_diskProvider.DeleteFolder(series.Path, true);
}
else if (_diskProvider.GetFiles(seasonFolder, SearchOption.AllDirectories).Empty())
if (_diskProvider.FolderExists(folder))
{
_diskProvider.RemoveEmptySubfolders(seasonFolder);
_diskProvider.RemoveEmptySubfolders(folder);
}
folder = folder.GetParentPath();
}
_diskProvider.RemoveEmptySubfolders(seriesPath);
if (_diskProvider.FolderEmpty(seriesPath))
{
_diskProvider.DeleteFolder(seriesPath, true);
}
}
}