< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.AppBase.BaseApplicationPaths
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs
Line coverage
62%
Covered lines: 18
Uncovered lines: 11
Coverable lines: 29
Total lines: 123
Line coverage: 62%
Branch coverage
83%
Covered branches: 5
Total branches: 6
Branch coverage: 83.3%
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_VirtualDataPath()100%11100%
get_ImageCachePath()100%210%
get_PluginsPath()100%11100%
get_PluginConfigurationsPath()100%11100%
get_SystemConfigurationFilePath()100%11100%
get_TempDirectory()100%11100%
get_TrickplayPath()100%210%
get_BackupPath()100%210%
MakeSanityCheckOrThrow()100%210%
CreateAndCheckMarker(...)100%11100%
GetMarkers(...)100%22100%
CheckOrCreateMarker(...)75%4485.71%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/AppBase/BaseApplicationPaths.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using System.IO;
 4using System.Linq;
 5using Jellyfin.Extensions;
 6using MediaBrowser.Common.Configuration;
 7
 8namespace Emby.Server.Implementations.AppBase
 9{
 10    /// <summary>
 11    /// Provides a base class to hold common application paths used by both the UI and Server.
 12    /// This can be subclassed to add application-specific paths.
 13    /// </summary>
 14    public abstract class BaseApplicationPaths : IApplicationPaths
 15    {
 16        /// <summary>
 17        /// Initializes a new instance of the <see cref="BaseApplicationPaths"/> class.
 18        /// </summary>
 19        /// <param name="programDataPath">The program data path.</param>
 20        /// <param name="logDirectoryPath">The log directory path.</param>
 21        /// <param name="configurationDirectoryPath">The configuration directory path.</param>
 22        /// <param name="cacheDirectoryPath">The cache directory path.</param>
 23        /// <param name="webDirectoryPath">The web directory path.</param>
 24        protected BaseApplicationPaths(
 25            string programDataPath,
 26            string logDirectoryPath,
 27            string configurationDirectoryPath,
 28            string cacheDirectoryPath,
 29            string webDirectoryPath)
 30        {
 31            ProgramDataPath = programDataPath;
 32            LogDirectoryPath = logDirectoryPath;
 33            ConfigurationDirectoryPath = configurationDirectoryPath;
 2134            CachePath = cacheDirectoryPath;
 35            WebPath = webDirectoryPath;
 2136            DataPath = Directory.CreateDirectory(Path.Combine(ProgramDataPath, "data")).FullName;
 2137        }
 38
 39        /// <inheritdoc/>
 40        public string ProgramDataPath { get; }
 41
 42        /// <inheritdoc/>
 43        public string WebPath { get; }
 44
 45        /// <inheritdoc/>
 46        public string ProgramSystemPath { get; } = AppContext.BaseDirectory;
 47
 48        /// <inheritdoc/>
 49        public string DataPath { get; }
 50
 51        /// <inheritdoc />
 17752        public string VirtualDataPath => "%AppDataPath%";
 53
 54        /// <inheritdoc/>
 055        public string ImageCachePath => Path.Combine(CachePath, "images");
 56
 57        /// <inheritdoc/>
 29458        public string PluginsPath => Path.Combine(ProgramDataPath, "plugins");
 59
 60        /// <inheritdoc/>
 12661        public string PluginConfigurationsPath => Path.Combine(PluginsPath, "configurations");
 62
 63        /// <inheritdoc/>
 64        public string LogDirectoryPath { get; }
 65
 66        /// <inheritdoc/>
 67        public string ConfigurationDirectoryPath { get; }
 68
 69        /// <inheritdoc/>
 18570        public string SystemConfigurationFilePath => Path.Combine(ConfigurationDirectoryPath, "system.xml");
 71
 72        /// <inheritdoc/>
 73        public string CachePath { get; set; }
 74
 75        /// <inheritdoc/>
 7276        public string TempDirectory => Path.Join(Path.GetTempPath(), "jellyfin");
 77
 78        /// <inheritdoc />
 079        public string TrickplayPath => Path.Combine(DataPath, "trickplay");
 80
 81        /// <inheritdoc />
 082        public string BackupPath => Path.Combine(DataPath, "backups");
 83
 84        /// <inheritdoc />
 85        public virtual void MakeSanityCheckOrThrow()
 86        {
 087            CreateAndCheckMarker(ConfigurationDirectoryPath, "config");
 088            CreateAndCheckMarker(LogDirectoryPath, "log");
 089            CreateAndCheckMarker(PluginsPath, "plugin");
 090            CreateAndCheckMarker(ProgramDataPath, "data");
 091            CreateAndCheckMarker(CachePath, "cache");
 092            CreateAndCheckMarker(DataPath, "data");
 093        }
 94
 95        /// <inheritdoc />
 96        public void CreateAndCheckMarker(string path, string markerName, bool recursive = false)
 97        {
 16698            Directory.CreateDirectory(path);
 99
 166100            CheckOrCreateMarker(path, $".jellyfin-{markerName}", recursive);
 166101        }
 102
 103        private IEnumerable<string> GetMarkers(string path, bool recursive = false)
 104        {
 166105            return Directory.EnumerateFiles(path, ".jellyfin-*", recursive ? SearchOption.AllDirectories : SearchOption.
 106        }
 107
 108        private void CheckOrCreateMarker(string path, string markerName, bool recursive = false)
 109        {
 166110            var otherMarkers = GetMarkers(path, recursive).FirstOrDefault(e => Path.GetFileName(e) != markerName);
 166111            if (otherMarkers != null)
 112            {
 0113                throw new InvalidOperationException($"Exepected to find only {markerName} but found marker for {otherMar
 114            }
 115
 166116            var markerPath = Path.Combine(path, markerName);
 166117            if (!File.Exists(markerPath))
 118            {
 44119                FileHelper.CreateEmpty(markerPath);
 120            }
 166121        }
 122    }
 123}