mirror of
https://github.com/lidarr/lidarr.git
synced 2025-08-20 13:33:34 -07:00
Always access config file via provider to utilize lock
This commit is contained in:
parent
cdd683ae8f
commit
092e41264f
2 changed files with 36 additions and 3 deletions
|
@ -1,7 +1,11 @@
|
||||||
using System;
|
using System;
|
||||||
|
using System.Linq;
|
||||||
using NzbDrone.Common.Disk;
|
using NzbDrone.Common.Disk;
|
||||||
using NzbDrone.Common.EnvironmentInfo;
|
using NzbDrone.Common.EnvironmentInfo;
|
||||||
using NzbDrone.Common.Extensions;
|
using NzbDrone.Common.Extensions;
|
||||||
|
using NzbDrone.Core.Configuration;
|
||||||
|
using NzbDrone.Core.Lifecycle;
|
||||||
|
using NzbDrone.Core.Messaging.Events;
|
||||||
|
|
||||||
namespace NzbDrone.Core.Authentication
|
namespace NzbDrone.Core.Authentication
|
||||||
{
|
{
|
||||||
|
@ -15,17 +19,22 @@ namespace NzbDrone.Core.Authentication
|
||||||
User FindUser(Guid identifier);
|
User FindUser(Guid identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
public class UserService : IUserService
|
public class UserService : IUserService, IHandle<ApplicationStartedEvent>
|
||||||
{
|
{
|
||||||
private readonly IUserRepository _repo;
|
private readonly IUserRepository _repo;
|
||||||
private readonly IAppFolderInfo _appFolderInfo;
|
private readonly IAppFolderInfo _appFolderInfo;
|
||||||
private readonly IDiskProvider _diskProvider;
|
private readonly IDiskProvider _diskProvider;
|
||||||
|
private readonly IConfigFileProvider _configFileProvider;
|
||||||
|
|
||||||
public UserService(IUserRepository repo, IAppFolderInfo appFolderInfo, IDiskProvider diskProvider)
|
public UserService(IUserRepository repo,
|
||||||
|
IAppFolderInfo appFolderInfo,
|
||||||
|
IDiskProvider diskProvider,
|
||||||
|
IConfigFileProvider configFileProvider)
|
||||||
{
|
{
|
||||||
_repo = repo;
|
_repo = repo;
|
||||||
_appFolderInfo = appFolderInfo;
|
_appFolderInfo = appFolderInfo;
|
||||||
_diskProvider = diskProvider;
|
_diskProvider = diskProvider;
|
||||||
|
_configFileProvider = configFileProvider;
|
||||||
}
|
}
|
||||||
|
|
||||||
public User Add(string username, string password)
|
public User Add(string username, string password)
|
||||||
|
@ -93,5 +102,28 @@ namespace NzbDrone.Core.Authentication
|
||||||
{
|
{
|
||||||
return _repo.FindUser(identifier);
|
return _repo.FindUser(identifier);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void Handle(ApplicationStartedEvent message)
|
||||||
|
{
|
||||||
|
if (_repo.All().Any())
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var xDoc = _configFileProvider.LoadConfigFile();
|
||||||
|
var config = xDoc.Descendants("Config").Single();
|
||||||
|
var usernameElement = config.Descendants("Username").FirstOrDefault();
|
||||||
|
var passwordElement = config.Descendants("Password").FirstOrDefault();
|
||||||
|
|
||||||
|
if (usernameElement == null || passwordElement == null)
|
||||||
|
{
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var username = usernameElement.Value;
|
||||||
|
var password = passwordElement.Value;
|
||||||
|
|
||||||
|
Add(username, password);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,6 +22,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>,
|
public interface IConfigFileProvider : IHandleAsync<ApplicationStartedEvent>,
|
||||||
IExecute<ResetApiKeyCommand>
|
IExecute<ResetApiKeyCommand>
|
||||||
{
|
{
|
||||||
|
XDocument LoadConfigFile();
|
||||||
Dictionary<string, object> GetConfigDictionary();
|
Dictionary<string, object> GetConfigDictionary();
|
||||||
void SaveConfigDictionary(Dictionary<string, object> configValues);
|
void SaveConfigDictionary(Dictionary<string, object> configValues);
|
||||||
void EnsureDefaultConfigFile();
|
void EnsureDefaultConfigFile();
|
||||||
|
@ -342,7 +343,7 @@ namespace NzbDrone.Core.Configuration
|
||||||
SaveConfigFile(xDoc);
|
SaveConfigFile(xDoc);
|
||||||
}
|
}
|
||||||
|
|
||||||
private XDocument LoadConfigFile()
|
public XDocument LoadConfigFile()
|
||||||
{
|
{
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue