mirror of
https://github.com/Readarr/Readarr.git
synced 2026-04-18 21:34:28 -04:00
b016b36435
Fixes #1712 Close #1713 (cherry picked from commit 0991cfe27efd6ddb533227b25754661e18d7e9ad)
45 lines
1.2 KiB
C#
45 lines
1.2 KiB
C#
using FluentValidation.Validators;
|
|
using NzbDrone.Common.EnvironmentInfo;
|
|
using NzbDrone.Common.Extensions;
|
|
|
|
namespace NzbDrone.Core.Validation.Paths
|
|
{
|
|
public class StartupFolderValidator : PropertyValidator
|
|
{
|
|
private readonly IAppFolderInfo _appFolderInfo;
|
|
|
|
public StartupFolderValidator(IAppFolderInfo appFolderInfo)
|
|
: base("Path cannot be {relationship} the start up folder")
|
|
{
|
|
_appFolderInfo = appFolderInfo;
|
|
}
|
|
|
|
protected override bool IsValid(PropertyValidatorContext context)
|
|
{
|
|
if (context.PropertyValue == null)
|
|
{
|
|
return true;
|
|
}
|
|
|
|
var startupFolder = _appFolderInfo.StartUpFolder;
|
|
var folder = context.PropertyValue.ToString();
|
|
|
|
if (startupFolder.PathEquals(folder))
|
|
{
|
|
context.MessageFormatter.AppendArgument("relationship", "set to");
|
|
|
|
return false;
|
|
}
|
|
|
|
if (startupFolder.IsParentPath(folder))
|
|
{
|
|
context.MessageFormatter.AppendArgument("relationship", "child of");
|
|
|
|
return false;
|
|
}
|
|
|
|
return true;
|
|
}
|
|
}
|
|
}
|