< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.Resolvers.SpecialFolderResolver
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/SpecialFolderResolver.cs
Line coverage
100%
Covered lines: 33
Uncovered lines: 0
Coverable lines: 33
Total lines: 86
Line coverage: 100%
Branch coverage
100%
Covered branches: 8
Total branches: 8
Branch coverage: 100%
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_Priority()100%11100%
Resolve(...)100%88100%
GetCollectionType(...)100%11100%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/Resolvers/SpecialFolderResolver.cs

#LineLine coverage
 1#nullable disable
 2
 3#pragma warning disable CS1591
 4
 5using System;
 6using System.IO;
 7using System.Linq;
 8using Jellyfin.Data.Enums;
 9using MediaBrowser.Controller;
 10using MediaBrowser.Controller.Entities;
 11using MediaBrowser.Controller.Library;
 12using MediaBrowser.Controller.Resolvers;
 13using MediaBrowser.Model.IO;
 14
 15namespace Emby.Server.Implementations.Library.Resolvers
 16{
 17    public class SpecialFolderResolver : GenericFolderResolver<Folder>
 18    {
 19        private readonly IFileSystem _fileSystem;
 20        private readonly IServerApplicationPaths _appPaths;
 21
 2222        public SpecialFolderResolver(IFileSystem fileSystem, IServerApplicationPaths appPaths)
 23        {
 2224            _fileSystem = fileSystem;
 2225            _appPaths = appPaths;
 2226        }
 27
 28        /// <summary>
 29        /// Gets the priority.
 30        /// </summary>
 31        /// <value>The priority.</value>
 2232        public override ResolverPriority Priority => ResolverPriority.First;
 33
 34        /// <summary>
 35        /// Resolves the specified args.
 36        /// </summary>
 37        /// <param name="args">The args.</param>
 38        /// <returns>Folder.</returns>
 39        protected override Folder Resolve(ItemResolveArgs args)
 40        {
 4941            if (args.IsDirectory)
 42            {
 4643                if (args.IsPhysicalRoot)
 44                {
 2245                    return new AggregateFolder();
 46                }
 47
 2448                if (string.Equals(args.Path, _appPaths.DefaultUserViewsPath, StringComparison.OrdinalIgnoreCase))
 49                {
 2250                    return new UserRootFolder();  // if we got here and still a root - must be user root
 51                }
 52
 253                if (args.IsVf)
 54                {
 255                    return new CollectionFolder
 256                    {
 257                        CollectionType = GetCollectionType(args),
 258                        PhysicalLocationsList = args.PhysicalLocations
 259                    };
 60                }
 61            }
 62
 363            return null;
 64        }
 65
 66        private CollectionType? GetCollectionType(ItemResolveArgs args)
 67        {
 268            return args.FileSystemChildren
 269                .Where(i =>
 270                {
 271                    try
 272                    {
 273                        return !i.IsDirectory &&
 274                               string.Equals(".collection", i.Extension, StringComparison.OrdinalIgnoreCase);
 275                    }
 276                    catch (IOException)
 277                    {
 278                        return false;
 279                    }
 280                })
 281                .Select(i => _fileSystem.GetFileNameWithoutExtension(i))
 282                .Select(i => Enum.TryParse<CollectionType>(i, out var collectionType) ? collectionType : (CollectionType
 283                .FirstOrDefault(i => i is not null);
 84        }
 85    }
 86}