New: Health check for import lists with missing root folders

New: Show missing root folder path in edit for Import List

Closes #4315
This commit is contained in:
Mark McDowall 2021-02-08 23:12:23 -08:00
parent 12fafb2457
commit ae196af2ad
5 changed files with 104 additions and 4 deletions

View File

@ -10,13 +10,16 @@ const ADD_NEW_KEY = 'addNew';
function createMapStateToProps() {
return createSelector(
(state) => state.rootFolders,
(state, { value }) => value,
(state, { includeMissingValue }) => includeMissingValue,
(state, { includeNoChange }) => includeNoChange,
(rootFolders, includeNoChange) => {
(rootFolders, value, includeMissingValue, includeNoChange) => {
const values = rootFolders.items.map((rootFolder) => {
return {
key: rootFolder.path,
value: rootFolder.path,
freeSpace: rootFolder.freeSpace
freeSpace: rootFolder.freeSpace,
isMissing: false
};
});
@ -24,7 +27,8 @@ function createMapStateToProps() {
values.unshift({
key: 'noChange',
value: 'No Change',
isDisabled: true
isDisabled: true,
isMissing: false
});
}
@ -37,6 +41,15 @@ function createMapStateToProps() {
});
}
if (includeMissingValue && !values.find((v) => v.key === value)) {
values.push({
key: value,
value,
isMissing: true,
isDisabled: true
});
}
values.push({
key: ADD_NEW_KEY,
value: 'Add a new path'

View File

@ -27,3 +27,9 @@
color: $darkGray;
font-size: $smallFontSize;
}
.isMissing {
margin-left: 15px;
color: $dangerColor;
font-size: $smallFontSize;
}

View File

@ -10,6 +10,7 @@ function RootFolderSelectInputOption(props) {
id,
value,
freeSpace,
isMissing,
seriesFolder,
isMobile,
isWindows,
@ -43,11 +44,20 @@ function RootFolderSelectInputOption(props) {
</div>
{
freeSpace != null &&
freeSpace == null ?
null :
<div className={styles.freeSpace}>
{formatBytes(freeSpace)} Free
</div>
}
{
isMissing ?
<div className={styles.isMissing}>
Missing
</div> :
null
}
</div>
</EnhancedSelectInputOption>
);
@ -57,6 +67,7 @@ RootFolderSelectInputOption.propTypes = {
id: PropTypes.string.isRequired,
value: PropTypes.string.isRequired,
freeSpace: PropTypes.number,
isMissing: PropTypes.boolean,
seriesFolder: PropTypes.string,
isMobile: PropTypes.bool.isRequired,
isWindows: PropTypes.bool

View File

@ -131,6 +131,7 @@ function EditImportListModalContent(props) {
name="rootFolderPath"
helpText={'Root Folder list items will be added to'}
{...rootFolderPath}
includeMissingValue={true}
onChange={onInputChange}
/>
</FormGroup>

View File

@ -0,0 +1,69 @@
using System.Collections.Generic;
using System.Linq;
using NzbDrone.Common.Disk;
using NzbDrone.Core.ImportLists;
using NzbDrone.Core.MediaFiles.Events;
using NzbDrone.Core.RootFolders;
using NzbDrone.Core.Tv;
using NzbDrone.Core.Tv.Events;
namespace NzbDrone.Core.HealthCheck.Checks
{
[CheckOn(typeof(SeriesDeletedEvent))]
[CheckOn(typeof(SeriesMovedEvent))]
[CheckOn(typeof(EpisodeImportedEvent), CheckOnCondition.FailedOnly)]
[CheckOn(typeof(EpisodeImportFailedEvent), CheckOnCondition.SuccessfulOnly)]
public class ImportListRootFolderCheck : HealthCheckBase
{
private readonly IImportListFactory _importListFactory;
private readonly IDiskProvider _diskProvider;
public ImportListRootFolderCheck(IImportListFactory importListFactory, IDiskProvider diskProvider)
{
_importListFactory = importListFactory;
_diskProvider = diskProvider;
}
public override HealthCheck Check()
{
var importLists = _importListFactory.All();
var missingRootFolders = new Dictionary<string, List<ImportListDefinition>>();
foreach (var importList in importLists)
{
var rootFolderPath = importList.RootFolderPath;
if (missingRootFolders.ContainsKey(rootFolderPath))
{
missingRootFolders[rootFolderPath].Add(importList);
continue;
}
if (!_diskProvider.FolderExists(rootFolderPath))
{
missingRootFolders.Add(rootFolderPath, new List<ImportListDefinition> { importList });
}
}
if (missingRootFolders.Any())
{
if (missingRootFolders.Count == 1)
{
var missingRootFolder = missingRootFolders.First();
return new HealthCheck(GetType(), HealthCheckResult.Error, $"Missing root folder for import list(s): {FormatRootFolder(missingRootFolder.Key, missingRootFolder.Value)}", "#import_list_missing_root_folder");
}
var message = string.Format("Multiple root folders are missing for import lists: {0}", string.Join(" | ", missingRootFolders.Select(m => FormatRootFolder(m.Key, m.Value))));
return new HealthCheck(GetType(), HealthCheckResult.Error, message, "#import_list_missing_root_folder");
}
return new HealthCheck(GetType());
}
private string FormatRootFolder(string rootFolderPath, List<ImportListDefinition> importLists)
{
return $"{rootFolderPath} ({string.Join(", ", importLists.Select(l => l.Name))})";
}
}
}