< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.IO.FileData
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/IO/FileData.cs
Line coverage
65%
Covered lines: 21
Uncovered lines: 11
Coverable lines: 32
Total lines: 108
Line coverage: 65.6%
Branch coverage
83%
Covered branches: 15
Total branches: 18
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
GetFilteredFileSystemEntries(...)83.33%31.171865.62%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/IO/FileData.cs

#LineLine coverage
 1using System;
 2using System.Collections.Generic;
 3using MediaBrowser.Controller.Library;
 4using MediaBrowser.Controller.Providers;
 5using MediaBrowser.Model.IO;
 6using Microsoft.Extensions.Logging;
 7
 8namespace MediaBrowser.Controller.IO
 9{
 10    /// <summary>
 11    /// Provides low level File access that is much faster than the File/Directory api's.
 12    /// </summary>
 13    public static class FileData
 14    {
 15        /// <summary>
 16        /// Gets the filtered file system entries.
 17        /// </summary>
 18        /// <param name="directoryService">The directory service.</param>
 19        /// <param name="path">The path.</param>
 20        /// <param name="fileSystem">The file system.</param>
 21        /// <param name="appHost">The application host.</param>
 22        /// <param name="logger">The logger.</param>
 23        /// <param name="args">The args.</param>
 24        /// <param name="flattenFolderDepth">The flatten folder depth.</param>
 25        /// <param name="resolveShortcuts">if set to <c>true</c> [resolve shortcuts].</param>
 26        /// <returns>Dictionary{System.StringFileSystemInfo}.</returns>
 27        /// <exception cref="ArgumentNullException"><paramref name="path" /> is <c>null</c> or empty.</exception>
 28        public static FileSystemMetadata[] GetFilteredFileSystemEntries(
 29            IDirectoryService directoryService,
 30            string path,
 31            IFileSystem fileSystem,
 32            IServerApplicationHost appHost,
 33            ILogger logger,
 34            ItemResolveArgs args,
 35            int flattenFolderDepth = 0,
 36            bool resolveShortcuts = true)
 37        {
 20038            ArgumentException.ThrowIfNullOrEmpty(path);
 39
 20040            ArgumentNullException.ThrowIfNull(args);
 41
 20042            var entries = directoryService.GetFileSystemEntries(path);
 43
 20044            if (!resolveShortcuts && flattenFolderDepth == 0)
 45            {
 2246                return entries;
 47            }
 48
 17849            var dict = new Dictionary<string, FileSystemMetadata>(StringComparer.OrdinalIgnoreCase);
 50
 55651            foreach (var entry in entries)
 52            {
 10053                var isDirectory = entry.IsDirectory;
 54
 10055                var fullName = entry.FullName;
 56
 10057                if (resolveShortcuts && fileSystem.IsShortcut(fullName))
 58                {
 59                    try
 60                    {
 061                        var newPath = appHost.ExpandVirtualPath(fileSystem.ResolveShortcut(fullName));
 62
 063                        if (string.IsNullOrEmpty(newPath))
 64                        {
 65                            // invalid shortcut - could be old or target could just be unavailable
 066                            logger.LogWarning("Encountered invalid shortcut: {Path}", fullName);
 067                            continue;
 68                        }
 69
 70                        // Don't check if it exists here because that could return false for network shares.
 071                        var data = fileSystem.GetDirectoryInfo(newPath);
 72
 73                        // add to our physical locations
 074                        args.AddAdditionalLocation(newPath);
 75
 076                        dict[newPath] = data;
 077                    }
 078                    catch (Exception ex)
 79                    {
 080                        logger.LogError(ex, "Error resolving shortcut from {Path}", fullName);
 081                    }
 82                }
 10083                else if (flattenFolderDepth > 0 && isDirectory)
 84                {
 18885                    foreach (var child in GetFilteredFileSystemEntries(directoryService, fullName, fileSystem, appHost, 
 86                    {
 887                        dict[child.FullName] = child;
 88                    }
 89                }
 90                else
 91                {
 1492                    dict[fullName] = entry;
 93                }
 94            }
 95
 17896            var returnResult = new FileSystemMetadata[dict.Count];
 17897            var index = 0;
 17898            var values = dict.Values;
 40099            foreach (var value in values)
 100            {
 22101                returnResult[index] = value;
 22102                index++;
 103            }
 104
 178105            return returnResult;
 106        }
 107    }
 108}