From 172e4b305c50d76450e5685eb2def6ea7f131140 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Tue, 26 Mar 2024 10:51:33 +1100 Subject: [PATCH] ignore hidden directories --- .../Exclusions/DefaultDirectoryExclusions.cs | 14 +++++++++++--- src/Tests/SnippetFileFinderTests.cs | 10 ++++++++++ 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/src/MarkdownSnippets/Reading/Exclusions/DefaultDirectoryExclusions.cs b/src/MarkdownSnippets/Reading/Exclusions/DefaultDirectoryExclusions.cs index d22836b0..974e138b 100644 --- a/src/MarkdownSnippets/Reading/Exclusions/DefaultDirectoryExclusions.cs +++ b/src/MarkdownSnippets/Reading/Exclusions/DefaultDirectoryExclusions.cs @@ -4,14 +4,22 @@ public static class DefaultDirectoryExclusions { public static bool ShouldExcludeDirectory(string path) { - var suffix = Path.GetFileName(path).ToLowerInvariant(); - return suffix is + var suffix = Path + .GetFileName(path) + .ToLowerInvariant(); + if (suffix is ".git" or ".vs" or ".idea" or "packages" or "node_modules" or "bin" or - "obj"; + "obj") + { + return true; + } + + var directory = new DirectoryInfo(path); + return directory.Attributes.HasFlag(FileAttributes.Hidden); } } \ No newline at end of file diff --git a/src/Tests/SnippetFileFinderTests.cs b/src/Tests/SnippetFileFinderTests.cs index ce6344da..be372b18 100644 --- a/src/Tests/SnippetFileFinderTests.cs +++ b/src/Tests/SnippetFileFinderTests.cs @@ -3,6 +3,16 @@ public class SnippetFileFinderTests { + [Fact] + public void Hidden() + { + var path = Path.Combine(Path.GetTempPath(), "mdsnippetsHidden"); + var directory = new DirectoryInfo(path); + directory.Create(); + directory.Attributes = FileAttributes.Directory | FileAttributes.Hidden; + Assert.True(DefaultDirectoryExclusions.ShouldExcludeDirectory(path)); + } + [Fact] public Task Nested() {