< 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
54%
Covered lines: 13
Uncovered lines: 11
Coverable lines: 24
Total lines: 77
Line coverage: 54.1%
Branch coverage
50%
Covered branches: 5
Total branches: 10
Branch coverage: 50%
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
FindIgnoreFile(...)75%4485.71%
ShouldIgnore(...)100%11100%
IsIgnored(...)33.33%15637.5%

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    {
 69016        var ignoreFile = new FileInfo(Path.Join(directory.FullName, ".ignore"));
 69017        if (ignoreFile.Exists)
 18        {
 019            return ignoreFile;
 20        }
 21
 69022        var parentDir = directory.Parent;
 69023        if (parentDir is null)
 24        {
 11225            return null;
 26        }
 27
 57828        return FindIgnoreFile(parentDir);
 29    }
 30
 31    /// <inheritdoc />
 32    public bool ShouldIgnore(FileSystemMetadata fileInfo, BaseItem? parent)
 33    {
 7834        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    {
 11245        var parentDirPath = Path.GetDirectoryName(fileInfo.FullName);
 11246        if (string.IsNullOrEmpty(parentDirPath))
 47        {
 048            return false;
 49        }
 50
 11251        var folder = new DirectoryInfo(parentDirPath);
 11252        var ignoreFile = FindIgnoreFile(folder);
 11253        if (ignoreFile is null)
 54        {
 11255            return false;
 56        }
 57
 58        string ignoreFileString;
 059        using (var reader = ignoreFile.OpenText())
 60        {
 061            ignoreFileString = reader.ReadToEnd();
 062        }
 63
 064        if (string.IsNullOrEmpty(ignoreFileString))
 65        {
 66            // Ignore directory if we just have the file
 067            return true;
 68        }
 69
 70        // If file has content, base ignoring off the content .gitignore-style rules
 071        var ignoreRules = ignoreFileString.Split('\n', StringSplitOptions.RemoveEmptyEntries);
 072        var ignore = new Ignore.Ignore();
 073        ignore.Add(ignoreRules);
 74
 075        return ignore.IsIgnored(fileInfo.FullName);
 76    }
 77}