< Summary - Jellyfin

Information
Class: Emby.Server.Implementations.Library.DotIgnoreIgnoreRule
Assembly: Emby.Server.Implementations
File(s): /srv/git/jellyfin/Emby.Server.Implementations/Library/DotIgnoreIgnoreRule.cs
Line coverage
48%
Covered lines: 17
Uncovered lines: 18
Coverable lines: 35
Total lines: 106
Line coverage: 48.5%
Branch coverage
36%
Covered branches: 8
Total branches: 22
Branch coverage: 36.3%
Method coverage

Feature is only available for sponsors

Upgrade to PRO version

Coverage history

Coverage history 0 25 50 75 100 7/22/2025 - 12:11:20 AM Line coverage: 54.1% (13/24) Branch coverage: 50% (5/10) Total lines: 777/29/2025 - 12:11:08 AM Line coverage: 56.6% (17/30) Branch coverage: 57.1% (8/14) Total lines: 949/13/2025 - 12:11:04 AM Line coverage: 51.5% (17/33) Branch coverage: 44.4% (8/18) Total lines: 10110/28/2025 - 12:11:27 AM Line coverage: 48.5% (17/35) Branch coverage: 36.3% (8/22) Total lines: 106 7/22/2025 - 12:11:20 AM Line coverage: 54.1% (13/24) Branch coverage: 50% (5/10) Total lines: 777/29/2025 - 12:11:08 AM Line coverage: 56.6% (17/30) Branch coverage: 57.1% (8/14) Total lines: 949/13/2025 - 12:11:04 AM Line coverage: 51.5% (17/33) Branch coverage: 44.4% (8/18) Total lines: 10110/28/2025 - 12:11:27 AM Line coverage: 48.5% (17/35) Branch coverage: 36.3% (8/22) Total lines: 106

Metrics

MethodBranch coverage Crap Score Cyclomatic complexity Line coverage
FindIgnoreFile(...)75%4485.71%
ShouldIgnore(...)100%11100%
IsIgnored(...)35.71%421447.61%
GetFileContent(...)0%2040%

File(s)

/srv/git/jellyfin/Emby.Server.Implementations/Library/DotIgnoreIgnoreRule.cs

#LineLine coverage
 1using System;
 2using System.IO;
 3using MediaBrowser.Controller.Entities;
 4using MediaBrowser.Controller.Resolvers;
 5using MediaBrowser.Model.IO;
 6
 7namespace Emby.Server.Implementations.Library;
 8
 9/// <summary>
 10/// Resolver rule class for ignoring files via .ignore.
 11/// </summary>
 12public class DotIgnoreIgnoreRule : IResolverIgnoreRule
 13{
 14    private static FileInfo? FindIgnoreFile(DirectoryInfo directory)
 15    {
 82116        var ignoreFile = new FileInfo(Path.Join(directory.FullName, ".ignore"));
 82117        if (ignoreFile.Exists)
 18        {
 019            return ignoreFile;
 20        }
 21
 82122        var parentDir = directory.Parent;
 82123        if (parentDir is null)
 24        {
 12025            return null;
 26        }
 27
 70128        return FindIgnoreFile(parentDir);
 29    }
 30
 31    /// <inheritdoc />
 32    public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem? parent)
 33    {
 8634        return IsIgnored(fileInfo, parent);
 35    }
 36
 37    /// <summary>
 38    /// Checks whether or not the file is ignored.
 39    /// </summary>
 40    /// <param name="fileInfo">The file information.</param>
 41    /// <param name="parent">The parent BaseItem.</param>
 42    /// <returns>True if the file should be ignored.</returns>
 43    public static bool IsIgnored(FileSystemMetadata fileInfo, BaseItem? parent)
 44    {
 12045        if (fileInfo.IsDirectory)
 46        {
 6347            var dirIgnoreFile = FindIgnoreFile(new DirectoryInfo(fileInfo.FullName));
 6348            if (dirIgnoreFile is null)
 49            {
 6350                return false;
 51            }
 52
 53            // Fast path in case the ignore files isn't a symlink and is empty
 054            if (dirIgnoreFile.LinkTarget is null && dirIgnoreFile.Length == 0)
 55            {
 056                return true;
 57            }
 58
 59            // ignore the directory only if the .ignore file is empty
 60            // evaluate individual files otherwise
 061            return string.IsNullOrWhiteSpace(GetFileContent(dirIgnoreFile));
 62        }
 63
 5764        var parentDirPath = Path.GetDirectoryName(fileInfo.FullName);
 5765        if (string.IsNullOrEmpty(parentDirPath))
 66        {
 067            return false;
 68        }
 69
 5770        var folder = new DirectoryInfo(parentDirPath);
 5771        var ignoreFile = FindIgnoreFile(folder);
 5772        if (ignoreFile is null)
 73        {
 5774            return false;
 75        }
 76
 077        string ignoreFileString = GetFileContent(ignoreFile);
 78
 079        if (string.IsNullOrWhiteSpace(ignoreFileString))
 80        {
 81            // Ignore directory if we just have the file
 082            return true;
 83        }
 84
 85        // If file has content, base ignoring off the content .gitignore-style rules
 086        var ignoreRules = ignoreFileString.Split('\n', StringSplitOptions.RemoveEmptyEntries);
 087        var ignore = new Ignore.Ignore();
 088        ignore.Add(ignoreRules);
 89
 090        return ignore.IsIgnored(fileInfo.FullName);
 91    }
 92
 93    private static string GetFileContent(FileInfo dirIgnoreFile)
 94    {
 095        dirIgnoreFile = (FileInfo?)dirIgnoreFile.ResolveLinkTarget(returnFinalTarget: true) ?? dirIgnoreFile;
 096        if (!dirIgnoreFile.Exists)
 97        {
 098            return string.Empty;
 99        }
 100
 0101        using (var reader = dirIgnoreFile.OpenText())
 102        {
 0103            return reader.ReadToEnd();
 104        }
 0105    }
 106}