< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Library.ItemResolveArgs
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Library/ItemResolveArgs.cs
Line coverage
59%
Covered lines: 28
Uncovered lines: 19
Coverable lines: 47
Total lines: 286
Line coverage: 59.5%
Branch coverage
39%
Covered branches: 15
Total branches: 38
Branch coverage: 39.4%
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_LibraryOptions()0%2040%
set_LibraryOptions(...)100%11100%
get_Path()100%11100%
get_IsDirectory()100%11100%
get_IsVf()66.66%6.29680%
get_IsPhysicalRoot()50%22100%
get_PhysicalLocations()50%44100%
HasParent()62.5%11.08863.63%
Equals(...)100%210%
AddAdditionalLocation(...)0%620%
GetFileSystemEntryByName(...)100%11100%
GetFileSystemEntryByPath(...)75%4.13480%
ContainsFileSystemEntryByName(...)100%11100%
GetCollectionType()100%11100%
GetConfiguredContentType()100%210%
GetHashCode()100%210%
Equals(...)0%7280%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Library/ItemResolveArgs.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.Collections.Generic;
 7using System.Linq;
 8using Jellyfin.Data.Enums;
 9using MediaBrowser.Controller.Entities;
 10using MediaBrowser.Model.Configuration;
 11using MediaBrowser.Model.IO;
 12
 13namespace MediaBrowser.Controller.Library
 14{
 15    /// <summary>
 16    /// These are arguments relating to the file system that are collected once and then referred to
 17    /// whenever needed.  Primarily for entity resolution.
 18    /// </summary>
 19    public class ItemResolveArgs
 20    {
 21        /// <summary>
 22        /// The _app paths.
 23        /// </summary>
 24        private readonly IServerApplicationPaths _appPaths;
 25
 26        private readonly ILibraryManager _libraryManager;
 27        private LibraryOptions _libraryOptions;
 28
 29        /// <summary>
 30        /// Initializes a new instance of the <see cref="ItemResolveArgs" /> class.
 31        /// </summary>
 32        /// <param name="appPaths">The app paths.</param>
 33        /// <param name="libraryManager">The library manager.</param>
 34        public ItemResolveArgs(IServerApplicationPaths appPaths, ILibraryManager libraryManager)
 35        {
 15536            _appPaths = appPaths;
 15537            _libraryManager = libraryManager;
 15538        }
 39
 40        /// <summary>
 41        /// Gets or sets the file system children.
 42        /// </summary>
 43        /// <value>The file system children.</value>
 44        public FileSystemMetadata[] FileSystemChildren { get; set; }
 45
 46        public LibraryOptions LibraryOptions
 47        {
 048            get => _libraryOptions ??= Parent is null ? new LibraryOptions() : _libraryManager.GetLibraryOptions(Parent)
 6649            set => _libraryOptions = value;
 50        }
 51
 52        /// <summary>
 53        /// Gets or sets the parent.
 54        /// </summary>
 55        /// <value>The parent.</value>
 56        public Folder Parent { get; set; }
 57
 58        /// <summary>
 59        /// Gets or sets the file info.
 60        /// </summary>
 61        /// <value>The file info.</value>
 62        public FileSystemMetadata FileInfo { get; set; }
 63
 64        /// <summary>
 65        /// Gets the path.
 66        /// </summary>
 67        /// <value>The path.</value>
 83268        public string Path => FileInfo.FullName;
 69
 70        /// <summary>
 71        /// Gets a value indicating whether this instance is directory.
 72        /// </summary>
 73        /// <value><c>true</c> if this instance is directory; otherwise, <c>false</c>.</value>
 56374        public bool IsDirectory => FileInfo.IsDirectory;
 75
 76        /// <summary>
 77        /// Gets a value indicating whether this instance is vf.
 78        /// </summary>
 79        /// <value><c>true</c> if this instance is vf; otherwise, <c>false</c>.</value>
 80        public bool IsVf
 81        {
 82            // we should be considered a virtual folder if we are a child of one of the children of the system root fold
 83            //  this is a bit of a trick to determine that...  the directory name of a sub-child of the root will start 
 84            //  the root but not be equal to it
 85            get
 86            {
 4887                if (!IsDirectory)
 88                {
 089                    return false;
 90                }
 91
 4892                var parentDir = System.IO.Path.GetDirectoryName(Path) ?? string.Empty;
 93
 4894                return parentDir.Length > _appPaths.RootFolderPath.Length
 4895                       && parentDir.StartsWith(_appPaths.RootFolderPath, StringComparison.OrdinalIgnoreCase);
 96            }
 97        }
 98
 99        /// <summary>
 100        /// Gets a value indicating whether this instance is physical root.
 101        /// </summary>
 102        /// <value><c>true</c> if this instance is physical root; otherwise, <c>false</c>.</value>
 92103        public bool IsPhysicalRoot => IsDirectory && BaseItem.FileSystem.AreEqual(Path, _appPaths.RootFolderPath);
 104
 105        /// <summary>
 106        /// Gets or sets the additional locations.
 107        /// </summary>
 108        /// <value>The additional locations.</value>
 109        private List<string> AdditionalLocations { get; set; }
 110
 111        /// <summary>
 112        /// Gets the physical locations.
 113        /// </summary>
 114        /// <value>The physical locations.</value>
 115        public string[] PhysicalLocations
 116        {
 117            get
 118            {
 121119                var paths = string.IsNullOrEmpty(Path) ? Array.Empty<string>() : [Path];
 121120                return AdditionalLocations is null ? paths : [..paths, ..AdditionalLocations];
 121            }
 122        }
 123
 124        public CollectionType? CollectionType { get; set; }
 125
 126        public bool HasParent<T>()
 127            where T : Folder
 128        {
 3129            var parent = Parent;
 130
 3131            if (parent is not null)
 132            {
 3133                var item = parent as T;
 134
 135                // Just in case the user decided to nest episodes.
 136                // Not officially supported but in some cases we can handle it.
 3137                if (item is null)
 138                {
 3139                    var parents = parent.GetParents();
 6140                    foreach (var currentParent in parents)
 141                    {
 0142                        if (currentParent is T)
 143                        {
 0144                            return true;
 145                        }
 146                    }
 147                }
 148
 3149                return item is not null;
 150            }
 151
 0152            return false;
 0153        }
 154
 155        /// <summary>
 156        /// Determines whether the specified <see cref="object" /> is equal to this instance.
 157        /// </summary>
 158        /// <param name="obj">The object to compare with the current object.</param>
 159        /// <returns><c>true</c> if the specified <see cref="object" /> is equal to this instance; otherwise, <c>false</
 160        public override bool Equals(object obj)
 161        {
 0162            return Equals(obj as ItemResolveArgs);
 163        }
 164
 165        /// <summary>
 166        /// Adds the additional location.
 167        /// </summary>
 168        /// <param name="path">The path.</param>
 169        /// <exception cref="ArgumentNullException"><paramref name="path"/> is <c>null</c> or empty.</exception>
 170        public void AddAdditionalLocation(string path)
 171        {
 0172            ArgumentException.ThrowIfNullOrEmpty(path);
 173
 0174            AdditionalLocations ??= new List<string>();
 0175            AdditionalLocations.Add(path);
 0176        }
 177
 178        // REVIEW: @bond
 179
 180        /// <summary>
 181        /// Gets the name of the file system entry by.
 182        /// </summary>
 183        /// <param name="name">The name.</param>
 184        /// <returns>FileSystemInfo.</returns>
 185        /// <exception cref="ArgumentNullException"><paramref name="name"/> is <c>null</c> or empty.</exception>
 186        public FileSystemMetadata GetFileSystemEntryByName(string name)
 187        {
 46188            ArgumentException.ThrowIfNullOrEmpty(name);
 189
 46190            return GetFileSystemEntryByPath(System.IO.Path.Combine(Path, name));
 191        }
 192
 193        /// <summary>
 194        /// Gets the file system entry by path.
 195        /// </summary>
 196        /// <param name="path">The path.</param>
 197        /// <returns>FileSystemInfo.</returns>
 198        /// <exception cref="ArgumentNullException">Throws if path is invalid.</exception>
 199        public FileSystemMetadata GetFileSystemEntryByPath(string path)
 200        {
 46201            ArgumentException.ThrowIfNullOrEmpty(path);
 202
 96203            foreach (var file in FileSystemChildren)
 204            {
 2205                if (string.Equals(file.FullName, path, StringComparison.Ordinal))
 206                {
 0207                    return file;
 208                }
 209            }
 210
 46211            return null;
 212        }
 213
 214        /// <summary>
 215        /// Determines whether [contains file system entry by name] [the specified name].
 216        /// </summary>
 217        /// <param name="name">The name.</param>
 218        /// <returns><c>true</c> if [contains file system entry by name] [the specified name]; otherwise, <c>false</c>.<
 219        public bool ContainsFileSystemEntryByName(string name)
 220        {
 46221            return GetFileSystemEntryByName(name) is not null;
 222        }
 223
 224        public CollectionType? GetCollectionType()
 225        {
 38226            return CollectionType;
 227        }
 228
 229        /// <summary>
 230        /// Gets the configured content type for the path.
 231        /// </summary>
 232        /// <returns>The configured content type.</returns>
 233        public CollectionType? GetConfiguredContentType()
 234        {
 0235            return _libraryManager.GetConfiguredContentType(Path);
 236        }
 237
 238        /// <summary>
 239        /// Gets the file system children that do not hit the ignore file check.
 240        /// </summary>
 241        /// <returns>The file system children that are not ignored.</returns>
 242        public IEnumerable<FileSystemMetadata> GetActualFileSystemChildren()
 243        {
 244            var numberOfChildren = FileSystemChildren.Length;
 245            for (var i = 0; i < numberOfChildren; i++)
 246            {
 247                var child = FileSystemChildren[i];
 248                if (_libraryManager.IgnoreFile(child, Parent))
 249                {
 250                    continue;
 251                }
 252
 253                yield return child;
 254            }
 255        }
 256
 257        /// <summary>
 258        /// Returns a hash code for this instance.
 259        /// </summary>
 260        /// <returns>A hash code for this instance, suitable for use in hashing algorithms and data structures like a ha
 261        public override int GetHashCode()
 262        {
 0263            return Path.GetHashCode(StringComparison.Ordinal);
 264        }
 265
 266        /// <summary>
 267        /// Equals the specified args.
 268        /// </summary>
 269        /// <param name="args">The args.</param>
 270        /// <returns><c>true</c> if the arguments are the same, <c>false</c> otherwise.</returns>
 271        protected bool Equals(ItemResolveArgs args)
 272        {
 0273            if (args is not null)
 274            {
 0275                if (args.Path is null && Path is null)
 276                {
 0277                    return true;
 278                }
 279
 0280                return args.Path is not null && BaseItem.FileSystem.AreEqual(args.Path, Path);
 281            }
 282
 0283            return false;
 284        }
 285    }
 286}