Always access config file via provider to utilise lock

pull/6279/head
ta264 4 years ago
parent 0a2afe692f
commit 36962f176f

@ -1,9 +1,9 @@
using System; using System;
using System.Linq; using System.Linq;
using System.Xml.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.Lifecycle;
using NzbDrone.Core.Messaging.Events; using NzbDrone.Core.Messaging.Events;
@ -24,12 +24,17 @@ namespace NzbDrone.Core.Authentication
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)
@ -105,14 +110,7 @@ namespace NzbDrone.Core.Authentication
return; return;
} }
var configFile = _appFolderInfo.GetConfigPath(); var xDoc = _configFileProvider.LoadConfigFile();
if (!_diskProvider.FileExists(configFile))
{
return;
}
var xDoc = XDocument.Load(configFile);
var config = xDoc.Descendants("Config").Single(); var config = xDoc.Descendants("Config").Single();
var usernameElement = config.Descendants("Username").FirstOrDefault(); var usernameElement = config.Descendants("Username").FirstOrDefault();
var passwordElement = config.Descendants("Password").FirstOrDefault(); var passwordElement = config.Descendants("Password").FirstOrDefault();

@ -21,6 +21,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);
@ -310,7 +311,7 @@ namespace NzbDrone.Core.Configuration
SaveConfigFile(xDoc); SaveConfigFile(xDoc);
} }
private XDocument LoadConfigFile() public XDocument LoadConfigFile()
{ {
try try
{ {

Loading…
Cancel
Save