< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Configuration.ServerConfigurationManager
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Configuration/ServerConfigurationManager.cs
Line coverage
46%
Covered lines: 14
Uncovered lines: 16
Coverable lines: 30
Total lines: 123
Line coverage: 46.6%
Branch coverage
10%
Covered branches: 1
Total branches: 10
Branch coverage: 10%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
get_ConfigurationType()100%11100%
get_ApplicationPaths()100%11100%
get_Configuration()100%11100%
OnConfigurationUpdated()100%11100%
UpdateMetadataPath()50%22100%
ReplaceConfiguration(...)0%620%
ValidateMetadataPath(...)0%4260%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Configuration/ServerConfigurationManager.cs

#LineLine coverage
 1using System;
 2using System.Globalization;
 3using System.IO;
 4using Emby.Server.Implementations.AppBase;
 5using Jellyfin.Data.Events;
 6using MediaBrowser.Common.Configuration;
 7using MediaBrowser.Controller;
 8using MediaBrowser.Controller.Configuration;
 9using MediaBrowser.Model.Configuration;
 10using MediaBrowser.Model.Serialization;
 11using Microsoft.Extensions.Logging;
 12
 13namespace Emby.Server.Implementations.Configuration
 14{
 15    /// <summary>
 16    /// Class ServerConfigurationManager.
 17    /// </summary>
 18    public class ServerConfigurationManager : BaseConfigurationManager, IServerConfigurationManager
 19    {
 20        /// <summary>
 21        /// Initializes a new instance of the <see cref="ServerConfigurationManager" /> class.
 22        /// </summary>
 23        /// <param name="applicationPaths">The application paths.</param>
 24        /// <param name="loggerFactory">The logger factory.</param>
 25        /// <param name="xmlSerializer">The XML serializer.</param>
 26        public ServerConfigurationManager(
 27            IApplicationPaths applicationPaths,
 28            ILoggerFactory loggerFactory,
 29            IXmlSerializer xmlSerializer)
 2230            : base(applicationPaths, loggerFactory, xmlSerializer)
 31        {
 2232            UpdateMetadataPath();
 2233        }
 34
 35        /// <summary>
 36        /// Configuration updating event.
 37        /// </summary>
 38        public event EventHandler<GenericEventArgs<ServerConfiguration>>? ConfigurationUpdating;
 39
 40        /// <summary>
 41        /// Gets the type of the configuration.
 42        /// </summary>
 43        /// <value>The type of the configuration.</value>
 2244        protected override Type ConfigurationType => typeof(ServerConfiguration);
 45
 46        /// <summary>
 47        /// Gets the application paths.
 48        /// </summary>
 49        /// <value>The application paths.</value>
 67950        public IServerApplicationPaths ApplicationPaths => (IServerApplicationPaths)CommonApplicationPaths;
 51
 52        /// <summary>
 53        /// Gets the configuration.
 54        /// </summary>
 55        /// <value>The configuration.</value>
 310056        public ServerConfiguration Configuration => (ServerConfiguration)CommonConfiguration;
 57
 58        /// <summary>
 59        /// Called when [configuration updated].
 60        /// </summary>
 61        protected override void OnConfigurationUpdated()
 62        {
 4063            UpdateMetadataPath();
 64
 4065            base.OnConfigurationUpdated();
 4066        }
 67
 68        /// <summary>
 69        /// Updates the metadata path.
 70        /// </summary>
 71        /// <exception cref="UnauthorizedAccessException">If the directory does not exist, and the caller does not have 
 72        /// <exception cref="NotSupportedException">If there is a custom path transcoding path specified, but it is inva
 73        /// <exception cref="IOException">If the directory does not exist, and it also could not be created.</exception>
 74        private void UpdateMetadataPath()
 75        {
 6276            ((ServerApplicationPaths)ApplicationPaths).InternalMetadataPath = string.IsNullOrWhiteSpace(Configuration.Me
 6277                ? ApplicationPaths.DefaultInternalMetadataPath
 6278                : Configuration.MetadataPath;
 6279            Directory.CreateDirectory(ApplicationPaths.InternalMetadataPath);
 6280        }
 81
 82        /// <summary>
 83        /// Replaces the configuration.
 84        /// </summary>
 85        /// <param name="newConfiguration">The new configuration.</param>
 86        /// <exception cref="DirectoryNotFoundException">If the configuration path doesn't exist.</exception>
 87        public override void ReplaceConfiguration(BaseApplicationConfiguration newConfiguration)
 88        {
 089            var newConfig = (ServerConfiguration)newConfiguration;
 90
 091            ValidateMetadataPath(newConfig);
 92
 093            ConfigurationUpdating?.Invoke(this, new GenericEventArgs<ServerConfiguration>(newConfig));
 94
 095            base.ReplaceConfiguration(newConfiguration);
 096        }
 97
 98        /// <summary>
 99        /// Validates the metadata path.
 100        /// </summary>
 101        /// <param name="newConfig">The new configuration.</param>
 102        /// <exception cref="DirectoryNotFoundException">The new config path doesn't exist.</exception>
 103        private void ValidateMetadataPath(ServerConfiguration newConfig)
 104        {
 0105            var newPath = newConfig.MetadataPath;
 106
 0107            if (!string.IsNullOrWhiteSpace(newPath)
 0108                && !string.Equals(Configuration.MetadataPath, newPath, StringComparison.Ordinal))
 109            {
 0110                if (!Directory.Exists(newPath))
 111                {
 0112                    throw new DirectoryNotFoundException(
 0113                        string.Format(
 0114                            CultureInfo.InvariantCulture,
 0115                            "{0} does not exist.",
 0116                            newPath));
 117                }
 118
 0119                EnsureWriteAccess(newPath);
 120            }
 0121        }
 122    }
 123}