From db899a9bb8c14ce28dbd61c37cdd594ae11bb284 Mon Sep 17 00:00:00 2001 From: Mark McDowall Date: Wed, 2 Nov 2016 11:11:55 -0700 Subject: [PATCH] New: Move subtitles/other extra files to Sonarr's Recycle Bin instead of permanently deleting --- .../Extras/Files/ExtraFileService.cs | 23 ++++++++++++++++++- .../MetaData/Files/MetadataFileService.cs | 13 +++++++++-- .../Extras/Others/OtherExtraFileService.cs | 5 ++-- .../Extras/Subtitles/SubtitleFileService.cs | 5 ++-- 4 files changed, 39 insertions(+), 7 deletions(-) diff --git a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs index d1fafd0d1..9a84a580b 100644 --- a/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs +++ b/src/NzbDrone.Core/Extras/Files/ExtraFileService.cs @@ -4,6 +4,7 @@ using System.IO; using System.Linq; using NLog; using NzbDrone.Common.Disk; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.MediaFiles.Events; using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Tv; @@ -31,19 +32,30 @@ namespace NzbDrone.Core.Extras.Files private readonly IExtraFileRepository _repository; private readonly ISeriesService _seriesService; private readonly IDiskProvider _diskProvider; + private readonly IRecycleBinProvider _recycleBinProvider; private readonly Logger _logger; public ExtraFileService(IExtraFileRepository repository, ISeriesService seriesService, IDiskProvider diskProvider, + IRecycleBinProvider recycleBinProvider, Logger logger) { _repository = repository; _seriesService = seriesService; _diskProvider = diskProvider; + _recycleBinProvider = recycleBinProvider; _logger = logger; } + public virtual bool PermanentlyDelete + { + get + { + return false; + } + } + public List GetFilesBySeries(int seriesId) { return _repository.GetFilesBySeries(seriesId); @@ -107,7 +119,16 @@ namespace NzbDrone.Core.Extras.Files if (_diskProvider.FileExists(path)) { - _diskProvider.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/Extras/MetaData/Files/MetadataFileService.cs b/src/NzbDrone.Core/Extras/MetaData/Files/MetadataFileService.cs index 2bb3d603d..ae14676c1 100644 --- a/src/NzbDrone.Core/Extras/MetaData/Files/MetadataFileService.cs +++ b/src/NzbDrone.Core/Extras/MetaData/Files/MetadataFileService.cs @@ -1,6 +1,7 @@ using NLog; using NzbDrone.Common.Disk; using NzbDrone.Core.Extras.Files; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Extras.Metadata.Files @@ -11,9 +12,17 @@ namespace NzbDrone.Core.Extras.Metadata.Files public class MetadataFileService : ExtraFileService, IMetadataFileService { - public MetadataFileService(IExtraFileRepository repository, ISeriesService seriesService, IDiskProvider diskProvider, Logger logger) - : base(repository, seriesService, diskProvider, logger) + public MetadataFileService(IExtraFileRepository repository, ISeriesService seriesService, IDiskProvider diskProvider, IRecycleBinProvider recycleBinProvider, Logger logger) + : base(repository, seriesService, diskProvider, recycleBinProvider, logger) { } + + public override bool PermanentlyDelete + { + get + { + return true; + } + } } } diff --git a/src/NzbDrone.Core/Extras/Others/OtherExtraFileService.cs b/src/NzbDrone.Core/Extras/Others/OtherExtraFileService.cs index 3d4f65c61..ceeb15ff8 100644 --- a/src/NzbDrone.Core/Extras/Others/OtherExtraFileService.cs +++ b/src/NzbDrone.Core/Extras/Others/OtherExtraFileService.cs @@ -1,6 +1,7 @@ using NLog; using NzbDrone.Common.Disk; using NzbDrone.Core.Extras.Files; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Extras.Others @@ -11,8 +12,8 @@ namespace NzbDrone.Core.Extras.Others public class OtherExtraFileService : ExtraFileService, IOtherExtraFileService { - public OtherExtraFileService(IExtraFileRepository repository, ISeriesService seriesService, IDiskProvider diskProvider, Logger logger) - : base(repository, seriesService, diskProvider, logger) + public OtherExtraFileService(IExtraFileRepository repository, ISeriesService seriesService, IDiskProvider diskProvider, IRecycleBinProvider recycleBinProvider, Logger logger) + : base(repository, seriesService, diskProvider, recycleBinProvider, logger) { } } diff --git a/src/NzbDrone.Core/Extras/Subtitles/SubtitleFileService.cs b/src/NzbDrone.Core/Extras/Subtitles/SubtitleFileService.cs index fe8ba4f3b..ac7d4da2b 100644 --- a/src/NzbDrone.Core/Extras/Subtitles/SubtitleFileService.cs +++ b/src/NzbDrone.Core/Extras/Subtitles/SubtitleFileService.cs @@ -1,6 +1,7 @@ using NLog; using NzbDrone.Common.Disk; using NzbDrone.Core.Extras.Files; +using NzbDrone.Core.MediaFiles; using NzbDrone.Core.Tv; namespace NzbDrone.Core.Extras.Subtitles @@ -11,8 +12,8 @@ namespace NzbDrone.Core.Extras.Subtitles public class SubtitleFileService : ExtraFileService, ISubtitleFileService { - public SubtitleFileService(IExtraFileRepository repository, ISeriesService seriesService, IDiskProvider diskProvider, Logger logger) - : base(repository, seriesService, diskProvider, logger) + public SubtitleFileService(IExtraFileRepository repository, ISeriesService seriesService, IDiskProvider diskProvider, IRecycleBinProvider recycleBinProvider, Logger logger) + : base(repository, seriesService, diskProvider, recycleBinProvider, logger) { } }