Skip to content

Commit

Permalink
Fix an issue with hidden file paths on Linux
Browse files Browse the repository at this point in the history
  • Loading branch information
Jeehut committed Apr 16, 2020
1 parent 9a510a7 commit 7e71f0f
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 11 deletions.
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ excluded:

disabled_rules:
- todo
- cyclomatic_complexity

# Rule Configurations
conditional_returns_on_newline:
Expand Down
27 changes: 16 additions & 11 deletions Sources/AnyLint/FilesSearch.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 7e71f0f

Please sign in to comment.