-
-
Notifications
You must be signed in to change notification settings - Fork 88
Fix hidden folder checking on Unix-based OS #574
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
5717941
879a550
db0b71c
bfd4f0e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -52,7 +52,7 @@ public static List<string> GetFiles(string folder, FileScannerConfig config) | |||||||||||||||||||||||||||||||||||||||
| List<string> filteredResult = unfilteredResult | ||||||||||||||||||||||||||||||||||||||||
| // Ignore hidden files and folders | ||||||||||||||||||||||||||||||||||||||||
| .Where(filePath => (!config.ExcludeHiddenFiles || !IsHiddenFile(filePath)) | ||||||||||||||||||||||||||||||||||||||||
| && (!config.ExcludeHiddenFolders || !IsInsideHiddenFolder(filePath))) | ||||||||||||||||||||||||||||||||||||||||
| && (!config.ExcludeHiddenFolders || !IsInsideHiddenFolder(filePath, folder))) | ||||||||||||||||||||||||||||||||||||||||
| .ToList(); | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| return filteredResult; | ||||||||||||||||||||||||||||||||||||||||
|
|
@@ -64,10 +64,15 @@ private static bool IsHiddenFile(string filePath) | |||||||||||||||||||||||||||||||||||||||
| return Path.GetFileName(filePath).StartsWith("."); | ||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||
| private static bool IsInsideHiddenFolder(string filePath) | ||||||||||||||||||||||||||||||||||||||||
| private static bool IsInsideHiddenFolder(string filePath, string rootPath) | ||||||||||||||||||||||||||||||||||||||||
| { | ||||||||||||||||||||||||||||||||||||||||
| // On Unix based operating systems, files and folders that start with a dot are hidden. | ||||||||||||||||||||||||||||||||||||||||
| string folderPath = Path.GetDirectoryName(filePath); | ||||||||||||||||||||||||||||||||||||||||
| return folderPath.Contains("\\.") || folderPath.Contains("/."); | ||||||||||||||||||||||||||||||||||||||||
| // Only check for hidden folders that are children of the root path, not the root path | ||||||||||||||||||||||||||||||||||||||||
| // itself or its parents. | ||||||||||||||||||||||||||||||||||||||||
| // We know rootPath is always a prefix of filePath, so it can be cut out with Substring(). | ||||||||||||||||||||||||||||||||||||||||
| // We also need to cut out the filename. Path.GetDirectoryName() can not be used here | ||||||||||||||||||||||||||||||||||||||||
| // because it removes duplicate and trailing slashes, changing the string length. | ||||||||||||||||||||||||||||||||||||||||
| string folderPath = filePath.Substring(rootPath.Length, filePath.LastIndexOfAny(new[] { '/', '\\' }) + 1 - rootPath.Length); | ||||||||||||||||||||||||||||||||||||||||
| return folderPath.StartsWith(".") || folderPath.Contains("\\.") || folderPath.Contains("/."); | ||||||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||||||
| return folderPath.StartsWith(".") || folderPath.Contains("\\.") || folderPath.Contains("/."); | |
| // Normalize the relative folder path and check each segment for a leading dot. | |
| if (string.IsNullOrEmpty(folderPath)) | |
| { | |
| return false; | |
| } | |
| folderPath = folderPath.TrimStart(Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar); | |
| if (folderPath.Length == 0) | |
| { | |
| return false; | |
| } | |
| string[] segments = folderPath.Split( | |
| new[] { Path.DirectorySeparatorChar, Path.AltDirectorySeparatorChar }, | |
| StringSplitOptions.RemoveEmptyEntries); | |
| return segments.Any(segment => segment.StartsWith(".")); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would be nice to have a common method for this. Currently, it is duplicated across DirectoryScanner and FileScanner.
Consider a HiddenFolderChecker or similar.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
FileScanner and DirectoryScanner seem to be duplicates of each other anyway, they could probably be merged.