1
0
mirror of https://github.com/Radarr/Radarr.git synced 2024-11-04 10:02:40 +01:00

New: Report health error if Recycling Bin folder is not writable

(cherry picked from commit 8c50cd061e691914d9fcce119b9f838f1276950c)

Fixes #8388
Closes #8389
This commit is contained in:
Mark McDowall 2023-04-24 20:23:20 -07:00 committed by Qstick
parent fddea0543c
commit a77cb25513
5 changed files with 79 additions and 2 deletions

View File

@ -0,0 +1,40 @@
using NzbDrone.Common.Disk;
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.Localization;
using NzbDrone.Core.MediaFiles.Events;
namespace NzbDrone.Core.HealthCheck.Checks
{
[CheckOn(typeof(MovieFileImportedEvent), CheckOnCondition.FailedOnly)]
[CheckOn(typeof(MovieImportFailedEvent), CheckOnCondition.SuccessfulOnly)]
public class RecyclingBinCheck : HealthCheckBase
{
private readonly IConfigService _configService;
private readonly IDiskProvider _diskProvider;
public RecyclingBinCheck(IConfigService configService, IDiskProvider diskProvider, ILocalizationService localizationService)
: base(localizationService)
{
_configService = configService;
_diskProvider = diskProvider;
}
public override HealthCheck Check()
{
var recycleBin = _configService.RecycleBin;
if (recycleBin.IsNullOrWhiteSpace())
{
return new HealthCheck(GetType());
}
if (!_diskProvider.FolderWritable(recycleBin))
{
return new HealthCheck(GetType(), HealthCheckResult.Error, string.Format(_localizationService.GetLocalizedString("RecycleBinUnableToWriteHealthCheck"), recycleBin), "#cannot-write-recycle-bin");
}
return new HealthCheck(GetType());
}
}
}

View File

@ -766,6 +766,7 @@
"RecycleBinCleanupDaysHelpText": "Set to 0 to disable automatic cleanup",
"RecycleBinCleanupDaysHelpTextWarning": "Files in the recycle bin older than the selected number of days will be cleaned up automatically",
"RecycleBinHelpText": "Movie files will go here when deleted instead of being permanently deleted",
"RecycleBinUnableToWriteHealthCheck": "Unable to write to configured recycling bin folder: {0}. Ensure this path exists and is writable by the user running Radarr",
"RecyclingBin": "Recycling Bin",
"RecyclingBinCleanup": "Recycling Bin Cleanup",
"Reddit": "Reddit",

View File

@ -164,6 +164,13 @@ public List<ImportResult> Import(List<ImportDecision> decisions, bool newDownloa
_commandQueueManager.Push(new RescanMovieCommand(localMovie.Movie.Id));
}
catch (RecycleBinException e)
{
_logger.Warn(e, "Couldn't import movie " + localMovie);
_eventAggregator.PublishEvent(new MovieImportFailedEvent(e, localMovie, newDownload, downloadClientItem));
importResults.Add(new ImportResult(importDecision, "Failed to import movie, unable to move existing file to the Recycle Bin."));
}
catch (Exception e)
{
_logger.Warn(e, "Couldn't import movie " + localMovie);

View File

@ -0,0 +1,28 @@
using System;
using System.IO;
using System.Runtime.Serialization;
namespace NzbDrone.Core.MediaFiles.MovieImport
{
public class RecycleBinException : DirectoryNotFoundException
{
public RecycleBinException()
{
}
public RecycleBinException(string message)
: base(message)
{
}
public RecycleBinException(string message, Exception innerException)
: base(message, innerException)
{
}
protected RecycleBinException(SerializationInfo info, StreamingContext context)
: base(info, context)
{
}
}
}

View File

@ -6,6 +6,7 @@
using NzbDrone.Common.Extensions;
using NzbDrone.Core.Configuration;
using NzbDrone.Core.MediaFiles.Commands;
using NzbDrone.Core.MediaFiles.MovieImport;
using NzbDrone.Core.Messaging.Commands;
namespace NzbDrone.Core.MediaFiles
@ -96,7 +97,7 @@ public void DeleteFile(string path, string subfolder = "")
catch (IOException e)
{
_logger.Error(e, "Unable to create the folder '{0}' in the recycling bin for the file '{1}'", destinationFolder, fileInfo.Name);
throw;
throw new RecycleBinException($"Unable to create the folder '{destinationFolder}' in the recycling bin for the file '{fileInfo.Name}'", e);
}
var index = 1;
@ -121,7 +122,7 @@ public void DeleteFile(string path, string subfolder = "")
catch (IOException e)
{
_logger.Error(e, "Unable to move '{0}' to the recycling bin: '{1}'", path, destination);
throw;
throw new RecycleBinException($"Unable to move '{path}' to the recycling bin: '{destination}'", e);
}
SetLastWriteTime(destination, DateTime.UtcNow);