From 7e71f0ffa7d9507b10a5f7f812b5f677469d2d24 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cihat=20Gu=CC=88ndu=CC=88z?= Date: Thu, 16 Apr 2020 17:22:03 +0200 Subject: [PATCH] Fix an issue with hidden file paths on Linux --- .swiftlint.yml | 1 + Sources/AnyLint/FilesSearch.swift | 27 ++++++++++++++++----------- 2 files changed, 17 insertions(+), 11 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index 6409aac..b51b982 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -87,6 +87,7 @@ excluded: disabled_rules: - todo + - cyclomatic_complexity # Rule Configurations conditional_returns_on_newline: diff --git a/Sources/AnyLint/FilesSearch.swift b/Sources/AnyLint/FilesSearch.swift index 179dcf8..3f53b33 100644 --- a/Sources/AnyLint/FilesSearch.swift +++ b/Sources/AnyLint/FilesSearch.swift @@ -10,12 +10,8 @@ public enum FilesSearch { return [] // only reachable in unit tests } - guard let enumerator = fileManager.enumerator( - at: url, - includingPropertiesForKeys: [URLResourceKey.isRegularFileKey, URLResourceKey.isHiddenKey], - options: [], - errorHandler: nil - ) else { + let propKeys = [URLResourceKey.isRegularFileKey, URLResourceKey.isHiddenKey] + guard let enumerator = fileManager.enumerator(at: url, includingPropertiesForKeys: propKeys, options: [], errorHandler: nil) else { log.message("Couldn't create enumerator for path '\(path)'.", level: .error) log.exit(status: .failure) return [] // only reachable in unit tests @@ -43,12 +39,21 @@ public enum FilesSearch { } // skip hidden files and directories - if isHiddenFilePath { - if !isRegularFilePath { - enumerator.skipDescendants() + #if os(Linux) + if isHiddenFilePath || fileUrl.path.contains("/.") || fileUrl.path.starts(with: ".") { + if !isRegularFilePath { + enumerator.skipDescendants() + } + continue } - continue - } + #else + if isHiddenFilePath { + if !isRegularFilePath { + enumerator.skipDescendants() + } + continue + } + #endif if isRegularFilePath, includeFilters.contains(where: { $0.matches(fileUrl.relativePathFromCurrent) }) { filePaths.append(fileUrl.relativePathFromCurrent)