make metadata path configurable

This commit is contained in:
Luke Pulverenti
2014-03-25 17:13:55 -04:00
parent 7c94203d05
commit 31e8288393
33 changed files with 204 additions and 339 deletions

View File

@@ -26,6 +26,7 @@ namespace MediaBrowser.Server.Implementations.Configuration
{
UpdateItemsByNamePath();
UpdateTranscodingTempPath();
UpdateMetadataPath();
}
/// <summary>
@@ -76,6 +77,16 @@ namespace MediaBrowser.Server.Implementations.Configuration
Configuration.ItemsByNamePath;
}
/// <summary>
/// Updates the metadata path.
/// </summary>
private void UpdateMetadataPath()
{
((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath = string.IsNullOrEmpty(Configuration.MetadataPath) ?
null :
Configuration.MetadataPath;
}
/// <summary>
/// Updates the transcoding temporary path.
/// </summary>
@@ -98,6 +109,7 @@ namespace MediaBrowser.Server.Implementations.Configuration
ValidateItemByNamePath(newConfig);
ValidateTranscodingTempPath(newConfig);
ValidatePathSubstitutions(newConfig);
ValidateMetadataPath(newConfig);
base.ReplaceConfiguration(newConfiguration);
}
@@ -166,5 +178,25 @@ namespace MediaBrowser.Server.Implementations.Configuration
}
}
}
/// <summary>
/// Validates the metadata path.
/// </summary>
/// <param name="newConfig">The new configuration.</param>
/// <exception cref="System.IO.DirectoryNotFoundException"></exception>
private void ValidateMetadataPath(ServerConfiguration newConfig)
{
var newPath = newConfig.MetadataPath;
if (!string.IsNullOrWhiteSpace(newPath)
&& !string.Equals(Configuration.MetadataPath ?? string.Empty, newPath))
{
// Validate
if (!Directory.Exists(newPath))
{
throw new DirectoryNotFoundException(string.Format("{0} does not exist.", newPath));
}
}
}
}
}

View File

@@ -260,6 +260,8 @@ namespace MediaBrowser.Server.Implementations.Library
public event EventHandler<GenericEventArgs<User>> UserCreated;
private readonly SemaphoreSlim _userListLock = new SemaphoreSlim(1, 1);
/// <summary>
/// Creates the user.
/// </summary>
@@ -279,19 +281,28 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentException(string.Format("A user with the name '{0}' already exists.", name));
}
var user = InstantiateNewUser(name);
await _userListLock.WaitAsync(CancellationToken.None).ConfigureAwait(false);
var list = Users.ToList();
list.Add(user);
Users = list;
try
{
var user = InstantiateNewUser(name);
user.DateLastSaved = DateTime.UtcNow;
var list = Users.ToList();
list.Add(user);
Users = list;
await UserRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false);
user.DateLastSaved = DateTime.UtcNow;
EventHelper.QueueEventIfNotNull(UserCreated, this, new GenericEventArgs<User> { Argument = user }, _logger);
await UserRepository.SaveUser(user, CancellationToken.None).ConfigureAwait(false);
return user;
EventHelper.QueueEventIfNotNull(UserCreated, this, new GenericEventArgs<User> { Argument = user }, _logger);
return user;
}
finally
{
_userListLock.Release();
}
}
/// <summary>
@@ -325,23 +336,32 @@ namespace MediaBrowser.Server.Implementations.Library
throw new ArgumentException(string.Format("The user '{0}' cannot be deleted because there must be at least one admin user in the system.", user.Name));
}
await UserRepository.DeleteUser(user, CancellationToken.None).ConfigureAwait(false);
var path = user.ConfigurationFilePath;
await _userListLock.WaitAsync(CancellationToken.None).ConfigureAwait(false);
try
{
File.Delete(path);
await UserRepository.DeleteUser(user, CancellationToken.None).ConfigureAwait(false);
var path = user.ConfigurationFilePath;
try
{
File.Delete(path);
}
catch (IOException ex)
{
_logger.ErrorException("Error deleting file {0}", ex, path);
}
// Force this to be lazy loaded again
Users = await LoadUsers().ConfigureAwait(false);
OnUserDeleted(user);
}
catch (IOException ex)
finally
{
_logger.ErrorException("Error deleting file {0}", ex, path);
_userListLock.Release();
}
// Force this to be lazy loaded again
Users = await LoadUsers().ConfigureAwait(false);
OnUserDeleted(user);
}
/// <summary>

View File

@@ -1,6 +1,6 @@
using System;
using MediaBrowser.Common.Implementations;
using MediaBrowser.Common.Implementations;
using MediaBrowser.Controller;
using System;
using System.IO;
namespace MediaBrowser.Server.Implementations
@@ -239,14 +239,20 @@ namespace MediaBrowser.Server.Implementations
}
}
private string _internalMetadataPath;
public string InternalMetadataPath
{
get
{
return Path.Combine(DataPath, "metadata");
return _internalMetadataPath ?? (_internalMetadataPath = Path.Combine(DataPath, "metadata"));
}
set
{
_internalMetadataPath = value;
}
}
public string GetInternalMetadataPath(Guid id)
{
var idString = id.ToString("N");