New: Move subtitles/other extra files to Sonarr's Recycle Bin instead of permanently deleting

This commit is contained in:
Mark McDowall 2016-11-02 11:11:55 -07:00
parent d3890bd712
commit db899a9bb8
4 changed files with 39 additions and 7 deletions

View File

@ -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<TExtraFile> _repository;
private readonly ISeriesService _seriesService;
private readonly IDiskProvider _diskProvider;
private readonly IRecycleBinProvider _recycleBinProvider;
private readonly Logger _logger;
public ExtraFileService(IExtraFileRepository<TExtraFile> 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<TExtraFile> GetFilesBySeries(int seriesId)
{
return _repository.GetFilesBySeries(seriesId);
@ -106,9 +118,18 @@ namespace NzbDrone.Core.Extras.Files
var path = Path.Combine(series.Path, extra.RelativePath);
if (_diskProvider.FileExists(path))
{
if (PermanentlyDelete)
{
_diskProvider.DeleteFile(path);
}
else
{
// Send extra files to the recycling bin so they can be recovered if necessary
_recycleBinProvider.DeleteFile(path);
}
}
}
_logger.Debug("Deleting Extra from database for episode file: {0}", episodeFile);

View File

@ -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<MetadataFile>, IMetadataFileService
{
public MetadataFileService(IExtraFileRepository<MetadataFile> repository, ISeriesService seriesService, IDiskProvider diskProvider, Logger logger)
: base(repository, seriesService, diskProvider, logger)
public MetadataFileService(IExtraFileRepository<MetadataFile> repository, ISeriesService seriesService, IDiskProvider diskProvider, IRecycleBinProvider recycleBinProvider, Logger logger)
: base(repository, seriesService, diskProvider, recycleBinProvider, logger)
{
}
public override bool PermanentlyDelete
{
get
{
return true;
}
}
}
}

View File

@ -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<OtherExtraFile>, IOtherExtraFileService
{
public OtherExtraFileService(IExtraFileRepository<OtherExtraFile> repository, ISeriesService seriesService, IDiskProvider diskProvider, Logger logger)
: base(repository, seriesService, diskProvider, logger)
public OtherExtraFileService(IExtraFileRepository<OtherExtraFile> repository, ISeriesService seriesService, IDiskProvider diskProvider, IRecycleBinProvider recycleBinProvider, Logger logger)
: base(repository, seriesService, diskProvider, recycleBinProvider, logger)
{
}
}

View File

@ -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<SubtitleFile>, ISubtitleFileService
{
public SubtitleFileService(IExtraFileRepository<SubtitleFile> repository, ISeriesService seriesService, IDiskProvider diskProvider, Logger logger)
: base(repository, seriesService, diskProvider, logger)
public SubtitleFileService(IExtraFileRepository<SubtitleFile> repository, ISeriesService seriesService, IDiskProvider diskProvider, IRecycleBinProvider recycleBinProvider, Logger logger)
: base(repository, seriesService, diskProvider, recycleBinProvider, logger)
{
}
}