< Summary - Jellyfin

Information
Class: MediaBrowser.Controller.Providers.DirectoryService
Assembly: MediaBrowser.Controller
File(s): /srv/git/jellyfin/MediaBrowser.Controller/Providers/DirectoryService.cs
Line coverage
100%
Covered lines: 62
Uncovered lines: 0
Coverable lines: 62
Total lines: 138
Line coverage: 100%
Branch coverage
100%
Covered branches: 24
Total branches: 24
Branch coverage: 100%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 1/23/2026 - 12:11:06 AM Line coverage: 97.3% (37/38) Branch coverage: 96.1% (25/26) Total lines: 1165/4/2026 - 12:15:16 AM Line coverage: 98.4% (63/64) Branch coverage: 96.1% (25/26) Total lines: 1435/6/2026 - 12:15:23 AM Line coverage: 100% (62/62) Branch coverage: 100% (24/24) Total lines: 138 1/23/2026 - 12:11:06 AM Line coverage: 97.3% (37/38) Branch coverage: 96.1% (25/26) Total lines: 1165/4/2026 - 12:15:16 AM Line coverage: 98.4% (63/64) Branch coverage: 96.1% (25/26) Total lines: 1435/6/2026 - 12:15:23 AM Line coverage: 100% (62/62) Branch coverage: 100% (24/24) Total lines: 138

Coverage delta

Coverage delta 4 -4

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
.ctor(...)100%11100%
GetFileSystemEntries(...)100%11100%
GetDirectories(...)100%44100%
GetFiles(...)100%44100%
GetFile(...)100%44100%
GetDirectory(...)100%44100%
GetFileSystemEntry(...)100%66100%
GetFilePaths(...)100%11100%
GetFilePaths(...)100%22100%
IsAccessible(...)100%11100%

File(s)

/srv/git/jellyfin/MediaBrowser.Controller/Providers/DirectoryService.cs

#LineLine coverage
 1#pragma warning disable CS1591
 2
 3using System;
 4using System.Collections.Concurrent;
 5using System.Collections.Generic;
 6using System.IO;
 7using System.Linq;
 8using MediaBrowser.Model.IO;
 9
 10namespace MediaBrowser.Controller.Providers
 11{
 12    public class DirectoryService : IDirectoryService
 13    {
 14        // TODO make static and switch to FastConcurrentLru.
 22215        private readonly ConcurrentDictionary<string, FileSystemMetadata[]> _cache = new(StringComparer.Ordinal);
 16
 22217        private readonly ConcurrentDictionary<string, FileSystemMetadata> _fileCache = new(StringComparer.Ordinal);
 18
 22219        private readonly ConcurrentDictionary<string, List<string>> _filePathCache = new(StringComparer.Ordinal);
 20
 21        private readonly IFileSystem _fileSystem;
 22
 23        public DirectoryService(IFileSystem fileSystem)
 24        {
 22225            _fileSystem = fileSystem;
 22226        }
 27
 28        public FileSystemMetadata[] GetFileSystemEntries(string path)
 29        {
 33730            return _cache.GetOrAdd(
 33731                path,
 33732                static (p, fileSystem) =>
 33733                {
 33734                    try
 33735                    {
 33736                        return fileSystem.GetFileSystemEntries(p).ToArray();
 33737                    }
 33738                    catch (DirectoryNotFoundException)
 33739                    {
 33740                        return [];
 33741                    }
 33742                },
 33743                _fileSystem);
 44        }
 45
 46        public List<FileSystemMetadata> GetDirectories(string path)
 47        {
 248            var list = new List<FileSystemMetadata>();
 249            var items = GetFileSystemEntries(path);
 1650            for (var i = 0; i < items.Length; i++)
 51            {
 652                var item = items[i];
 653                if (item.IsDirectory)
 54                {
 355                    list.Add(item);
 56                }
 57            }
 58
 259            return list;
 60        }
 61
 62        public List<FileSystemMetadata> GetFiles(string path)
 63        {
 264            var list = new List<FileSystemMetadata>();
 265            var items = GetFileSystemEntries(path);
 1666            for (var i = 0; i < items.Length; i++)
 67            {
 668                var item = items[i];
 669                if (!item.IsDirectory)
 70                {
 371                    list.Add(item);
 72                }
 73            }
 74
 275            return list;
 76        }
 77
 78        public FileSystemMetadata? GetFile(string path)
 79        {
 680            var entry = GetFileSystemEntry(path);
 681            return entry is not null && !entry.IsDirectory ? entry : null;
 82        }
 83
 84        public FileSystemMetadata? GetDirectory(string path)
 85        {
 486            var entry = GetFileSystemEntry(path);
 487            return entry is not null && entry.IsDirectory ? entry : null;
 88        }
 89
 90        public FileSystemMetadata? GetFileSystemEntry(string path)
 91        {
 4492            if (!_fileCache.TryGetValue(path, out var result))
 93            {
 4194                var file = _fileSystem.GetFileSystemInfo(path);
 4195                if (file?.Exists ?? false)
 96                {
 3797                    result = file;
 3798                    _fileCache.TryAdd(path, result);
 99                }
 100            }
 101
 44102            return result;
 103        }
 104
 105        public IReadOnlyList<string> GetFilePaths(string path)
 3106            => GetFilePaths(path, false);
 107
 108        public IReadOnlyList<string> GetFilePaths(string path, bool clearCache)
 109        {
 4110            if (clearCache)
 111            {
 1112                _filePathCache.TryRemove(path, out _);
 113            }
 114
 4115            var filePaths = _filePathCache.GetOrAdd(
 4116                path,
 4117                static (p, fileSystem) =>
 4118                {
 4119                    try
 4120                    {
 4121                        return fileSystem.GetFilePaths(p).OrderBy(x => x).ToList();
 4122                    }
 4123                    catch (DirectoryNotFoundException)
 4124                    {
 4125                        return [];
 4126                    }
 4127                },
 4128                _fileSystem);
 129
 4130            return filePaths;
 131        }
 132
 133        public bool IsAccessible(string path)
 134        {
 38135            return _fileSystem.GetFileSystemEntryPaths(path).Any();
 136        }
 137    }
 138}