aboutsummaryrefslogtreecommitdiff
path: root/MediaBrowser.Server.Implementations
diff options
context:
space:
mode:
authorLuke Pulverenti <luke.pulverenti@gmail.com>2014-03-25 17:13:55 -0400
committerLuke Pulverenti <luke.pulverenti@gmail.com>2014-03-25 17:13:55 -0400
commit31e8288393bead548e815a081c34d7e688fa0643 (patch)
tree0c81d134d1177d26d5462a02c8e82d1aea8745a3 /MediaBrowser.Server.Implementations
parent7c94203d05627483db68846f8b1dc88066a997f4 (diff)
make metadata path configurable
Diffstat (limited to 'MediaBrowser.Server.Implementations')
-rw-r--r--MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs32
-rw-r--r--MediaBrowser.Server.Implementations/Library/UserManager.cs58
-rw-r--r--MediaBrowser.Server.Implementations/ServerApplicationPaths.cs12
3 files changed, 80 insertions, 22 deletions
diff --git a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
index 415205cb1..cb3621fd1 100644
--- a/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
+++ b/MediaBrowser.Server.Implementations/Configuration/ServerConfigurationManager.cs
@@ -26,6 +26,7 @@ namespace MediaBrowser.Server.Implementations.Configuration
{
UpdateItemsByNamePath();
UpdateTranscodingTempPath();
+ UpdateMetadataPath();
}
/// <summary>
@@ -77,6 +78,16 @@ namespace MediaBrowser.Server.Implementations.Configuration
}
/// <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>
private void UpdateTranscodingTempPath()
@@ -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));
+ }
+ }
+ }
}
}
diff --git a/MediaBrowser.Server.Implementations/Library/UserManager.cs b/MediaBrowser.Server.Implementations/Library/UserManager.cs
index 06028d37e..2ee843f09 100644
--- a/MediaBrowser.Server.Implementations/Library/UserManager.cs
+++ b/MediaBrowser.Server.Implementations/Library/UserManager.cs
@@ -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>
diff --git a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs
index c36c49df0..df2a5f83c 100644
--- a/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs
+++ b/MediaBrowser.Server.Implementations/ServerApplicationPaths.cs
@@ -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");