mirror of
https://github.com/Sonarr/Sonarr.git
synced 2026-04-18 21:35:27 -04:00
Validate Special Folder Format doesn't match excluded folder
Closes #8339
This commit is contained in:
@@ -245,6 +245,28 @@ namespace NzbDrone.Core.MediaFiles
|
|||||||
return filteredPaths;
|
return filteredPaths;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static List<string> FilteredSubFolderMatches(string subfolder)
|
||||||
|
{
|
||||||
|
var matches = new List<string>();
|
||||||
|
|
||||||
|
foreach (var match in ExcludedSubFoldersRegex.Matches(subfolder))
|
||||||
|
{
|
||||||
|
matches.Add(match.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var match in ExcludedExtrasSubFolderRegex.Matches(subfolder))
|
||||||
|
{
|
||||||
|
matches.Add(match.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
foreach (var match in ExcludedExtraFilesRegex.Matches(subfolder))
|
||||||
|
{
|
||||||
|
matches.Add(match.ToString());
|
||||||
|
}
|
||||||
|
|
||||||
|
return matches;
|
||||||
|
}
|
||||||
|
|
||||||
private void SetPermissions(string path)
|
private void SetPermissions(string path)
|
||||||
{
|
{
|
||||||
if (!_configService.SetPermissionsLinux)
|
if (!_configService.SetPermissionsLinux)
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ using System.Text.RegularExpressions;
|
|||||||
using FluentValidation;
|
using FluentValidation;
|
||||||
using FluentValidation.Validators;
|
using FluentValidation.Validators;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.MediaFiles;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Organizer
|
namespace NzbDrone.Core.Organizer
|
||||||
{
|
{
|
||||||
@@ -59,8 +60,9 @@ namespace NzbDrone.Core.Organizer
|
|||||||
public static IRuleBuilderOptions<T, string> ValidSpecialsFolderFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
public static IRuleBuilderOptions<T, string> ValidSpecialsFolderFormat<T>(this IRuleBuilder<T, string> ruleBuilder)
|
||||||
{
|
{
|
||||||
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
ruleBuilder.SetValidator(new NotEmptyValidator(null));
|
||||||
|
ruleBuilder.SetValidator(new IllegalCharactersValidator());
|
||||||
|
|
||||||
return ruleBuilder.SetValidator(new IllegalCharactersValidator());
|
return ruleBuilder.SetValidator(new FilteredSubfolderValidator());
|
||||||
}
|
}
|
||||||
|
|
||||||
public static IRuleBuilderOptions<T, string> ValidCustomColonReplacement<T>(this IRuleBuilder<T, string> ruleBuilder)
|
public static IRuleBuilderOptions<T, string> ValidCustomColonReplacement<T>(this IRuleBuilder<T, string> ruleBuilder)
|
||||||
@@ -177,4 +179,32 @@ namespace NzbDrone.Core.Organizer
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public class FilteredSubfolderValidator : PropertyValidator
|
||||||
|
{
|
||||||
|
private static readonly char[] InvalidPathChars = Path.GetInvalidPathChars();
|
||||||
|
|
||||||
|
protected override string GetDefaultMessageTemplate() => "Matches excluded subfolder pattern: {FilteredSubfolders}";
|
||||||
|
|
||||||
|
protected override bool IsValid(PropertyValidatorContext context)
|
||||||
|
{
|
||||||
|
var value = context.PropertyValue as string;
|
||||||
|
|
||||||
|
if (value.IsNullOrWhiteSpace())
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
var subfolder = value + Path.DirectorySeparatorChar;
|
||||||
|
var matches = DiskScanService.FilteredSubFolderMatches(subfolder);
|
||||||
|
|
||||||
|
if (matches.Any())
|
||||||
|
{
|
||||||
|
context.MessageFormatter.AppendArgument("FilteredSubfolders", string.Join("", matches.Select(m => m.TrimEnd(Path.DirectorySeparatorChar))));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user