feat: New --app-data option for specifying app data directory

The target for this is mainly docker, where I want more control over
where and how the app data directory is structured and located.
pull/76/head
Robert Dailey 2 years ago
parent be9ae954f4
commit 43c44a9295

@ -0,0 +1,37 @@
using AutoFixture.NUnit3;
using NSubstitute;
using NUnit.Framework;
using Recyclarr.Command;
using Recyclarr.Command.Initialization.Init;
using TestLibrary.AutoFixture;
using TrashLib;
namespace Recyclarr.Tests.Command.Initialization.Init;
[TestFixture]
[Parallelizable(ParallelScope.All)]
public class InitializeAppDataPathTest
{
[Test, AutoMockData]
public void Do_not_override_path_if_null(
[Frozen] IAppPaths paths,
SonarrCommand cmd,
InitializeAppDataPath sut)
{
sut.Initialize(cmd);
paths.DidNotReceiveWithAnyArgs().SetAppDataPath(default!);
}
[Test, AutoMockData]
public void Override_path_if_not_null(
[Frozen] IAppPaths paths,
SonarrCommand cmd,
InitializeAppDataPath sut)
{
cmd.AppDataDirectory = "path";
sut.Initialize(cmd);
paths.Received().SetAppDataPath("path");
}
}

@ -0,0 +1,27 @@
using System.IO.Abstractions;
using TrashLib;
namespace Recyclarr.Command.Initialization.Init;
public class InitializeAppDataPath : IServiceInitializer
{
private readonly IFileSystem _fs;
private readonly IAppPaths _paths;
public InitializeAppDataPath(IFileSystem fs, IAppPaths paths)
{
_fs = fs;
_paths = paths;
}
public void Initialize(ServiceCommand cmd)
{
if (string.IsNullOrEmpty(cmd.AppDataDirectory))
{
return;
}
_fs.Directory.CreateDirectory(cmd.AppDataDirectory);
_paths.SetAppDataPath(cmd.AppDataDirectory);
}
}

@ -14,6 +14,7 @@ public class InitializationAutofacModule : Module
// Initialization Services
builder.RegisterTypes(
typeof(InitializeAppDataPath),
typeof(ServiceInitializer),
typeof(ServicePreInitializer))
.As<IServiceInitializer>()

@ -23,7 +23,12 @@ public abstract class ServiceCommand : ICommand, IServiceCommand
"If not specified, the script will look for `recyclarr.yml` in the same directory as the executable.")]
public ICollection<string> Config { get; [UsedImplicitly] set; } = new List<string>();
public abstract string CacheStoragePath { get; protected init; }
[CommandOption("app-data", Description =
"Explicitly specify the location of the recyclarr application data directory. " +
"Mainly for usage in Docker; not recommended for normal use.")]
public string? AppDataDirectory { get; [UsedImplicitly] set; }
public abstract string CacheStoragePath { get; [UsedImplicitly] protected init; }
public abstract string Name { get; }
protected ServiceCommand(IServiceInitializationAndCleanup init)

@ -9,6 +9,7 @@ namespace TrashLib.Repo;
public class RepoUpdater : IRepoUpdater
{
private readonly ILogger _log;
private readonly IAppPaths _paths;
private readonly IGitRepositoryFactory _repositoryFactory;
private readonly IFileUtilities _fileUtils;
private readonly ISettingsProvider _settingsProvider;
@ -21,13 +22,13 @@ public class RepoUpdater : IRepoUpdater
ISettingsProvider settingsProvider)
{
_log = log;
_paths = paths;
_repositoryFactory = repositoryFactory;
_fileUtils = fileUtils;
_settingsProvider = settingsProvider;
RepoPath = paths.RepoDirectory;
}
public string RepoPath { get; }
public string RepoPath => _paths.RepoDirectory;
public void UpdateRepo()
{

Loading…
Cancel
Save