From 7b09b259a8d269b3eb27d34951a2a7fb678c7e91 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 23 Nov 2016 16:38:40 -0800 Subject: [PATCH] Fixed: Don't delete extra files after unlinking an episode file that still exists on disk --- .../Extras/Files/ExtraFileService.cs | 31 ++++++++++++------- src/NzbDrone.Core/History/HistoryService.cs | 2 +- 2 files changed, 21 insertions(+), 12 deletions(-) diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs index 9a84a580b..d8e6b3fa7 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs @@ -111,23 +111,32 @@ namespace NzbDrone.Core.Extras.Files public void HandleAsync(EpisodeFileDeletedEvent message) { var episodeFile = message.EpisodeFile; - var series = _seriesService.GetSeries(message.EpisodeFile.SeriesId); - foreach (var extra in _repository.GetFilesByEpisodeFile(episodeFile.Id)) + if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes) { - var path = Path.Combine(series.Path, extra.RelativePath); + _logger.Debug("Removing episode file from DB as part of cleanup routine, not deleting extra files from disk."); + } - if (_diskProvider.FileExists(path)) + else + { + var series = _seriesService.GetSeries(message.EpisodeFile.SeriesId); + + foreach (var extra in _repository.GetFilesByEpisodeFile(episodeFile.Id)) { - if (PermanentlyDelete) - { - _diskProvider.DeleteFile(path); - } + var path = Path.Combine(series.Path, extra.RelativePath); - else + if (_diskProvider.FileExists(path)) { - // Send extra files to the recycling bin so they can be recovered if necessary - _recycleBinProvider.DeleteFile(path); + if (PermanentlyDelete) + { + _diskProvider.DeleteFile(path); + } + + else + { + // Send extra files to the recycling bin so they can be recovered if necessary + _recycleBinProvider.DeleteFile(path); + } } } } diff --git a/src/NzbDrone.Core/History/HistoryService.cs b/src/NzbDrone.Core/History/HistoryService.cs index 9459a4fcc..71d65e60e 100644 --- a/src/NzbDrone.Core/History/HistoryService.cs +++ b/src/NzbDrone.Core/History/HistoryService.cs @@ -236,7 +236,7 @@ namespace NzbDrone.Core.History { if (message.Reason == DeleteMediaFileReason.NoLinkedEpisodes) { - _logger.Debug("Removing episode file from DB as part of cleanup routine."); + _logger.Debug("Removing episode file from DB as part of cleanup routine, not creating history event."); return; }