Fixed: Deleting empty folders on upgrade

Fixes #4787
Fixes SENTRY RADARR-1F
pull/4810/head
Qstick 4 years ago
parent 695297435e
commit ec15885680

@ -122,23 +122,27 @@ namespace NzbDrone.Core.MediaFiles
[EventHandleOrder(EventHandleOrder.Last)]
public void Handle(MovieFileDeletedEvent message)
{
if (message.Reason == DeleteMediaFileReason.Upgrade)
{
return;
}
if (_configService.DeleteEmptyFolders)
{
var movie = message.MovieFile.Movie;
var movieFileFolder = message.MovieFile.Path.GetParentPath();
var moviePath = movie.Path;
var folder = message.MovieFile.Path.GetParentPath();
if (_diskProvider.GetFiles(movie.Path, SearchOption.AllDirectories).Empty())
while (moviePath.IsParentPath(folder))
{
_diskProvider.DeleteFolder(movie.Path, true);
if (_diskProvider.FolderExists(folder))
{
_diskProvider.RemoveEmptySubfolders(folder);
}
folder = folder.GetParentPath();
}
else if (_diskProvider.GetFiles(movieFileFolder, SearchOption.AllDirectories).Empty())
_diskProvider.RemoveEmptySubfolders(moviePath);
if (_diskProvider.FolderEmpty(moviePath))
{
_diskProvider.RemoveEmptySubfolders(movieFileFolder);
_diskProvider.DeleteFolder(moviePath, true);
}
}
}

Loading…
Cancel
Save