|
|
@ -4,13 +4,43 @@ using Recyclarr.TrashGuide;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Recyclarr.Config.Parsing.PostProcessing.ConfigMerging;
|
|
|
|
namespace Recyclarr.Config.Parsing.PostProcessing.ConfigMerging;
|
|
|
|
|
|
|
|
|
|
|
|
public class ConfigIncludeProcessor(IFileSystem fs, IAppPaths paths) : IIncludeProcessor
|
|
|
|
public class ConfigIncludeProcessor(IFileSystem fs, IAppPaths paths, ILogger log) : IIncludeProcessor
|
|
|
|
{
|
|
|
|
{
|
|
|
|
public bool CanProcess(IYamlInclude includeDirective)
|
|
|
|
public bool CanProcess(IYamlInclude includeDirective)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
return includeDirective is ConfigYamlInclude;
|
|
|
|
return includeDirective is ConfigYamlInclude;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private IFileInfo? ConvertToAbsolute(string path)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
if (fs.Path.IsPathRooted(path))
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
log.Debug("Path processed as absolute: {Path}", path);
|
|
|
|
|
|
|
|
return fs.FileInfo.New(path);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
var fsPath = paths.IncludesDirectory.File(path);
|
|
|
|
|
|
|
|
if (fsPath.Exists)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
log.Debug("Path rooted to the includes directory: {Path}", path);
|
|
|
|
|
|
|
|
return fsPath;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
fsPath = paths.ConfigsDirectory.File(path);
|
|
|
|
|
|
|
|
// ReSharper disable once InvertIf
|
|
|
|
|
|
|
|
if (fsPath.Exists)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
log.Warning(
|
|
|
|
|
|
|
|
"DEPRECATED: Include templates inside the `configs` directory are no longer supported. " +
|
|
|
|
|
|
|
|
"These files should be relocated to the new sibling `includes` directory instead. " +
|
|
|
|
|
|
|
|
"See: https://recyclarr.dev/wiki/upgrade-guide/v8.0/#include-dir");
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return fsPath;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public IFileInfo GetPathToConfig(IYamlInclude includeDirective, SupportedServices serviceType)
|
|
|
|
public IFileInfo GetPathToConfig(IYamlInclude includeDirective, SupportedServices serviceType)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var include = (ConfigYamlInclude) includeDirective;
|
|
|
|
var include = (ConfigYamlInclude) includeDirective;
|
|
|
@ -20,16 +50,10 @@ public class ConfigIncludeProcessor(IFileSystem fs, IAppPaths paths) : IIncludeP
|
|
|
|
throw new YamlIncludeException("`config` property is required.");
|
|
|
|
throw new YamlIncludeException("`config` property is required.");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var rooted = fs.Path.IsPathRooted(include.Config);
|
|
|
|
var configFile = ConvertToAbsolute(include.Config);
|
|
|
|
|
|
|
|
if (configFile?.Exists != true)
|
|
|
|
var configFile = rooted
|
|
|
|
|
|
|
|
? fs.FileInfo.New(include.Config)
|
|
|
|
|
|
|
|
: paths.ConfigsDirectory.File(include.Config);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!configFile.Exists)
|
|
|
|
|
|
|
|
{
|
|
|
|
{
|
|
|
|
var pathType = rooted ? "Absolute" : "Relative";
|
|
|
|
throw new YamlIncludeException($"Include path could not be resolved: {include.Config}");
|
|
|
|
throw new YamlIncludeException($"{pathType} include path does not exist: {configFile.FullName}");
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return configFile;
|
|
|
|
return configFile;
|
|
|
|