Skip to content

Commit

Permalink
Refactored symlink resolution
Browse files Browse the repository at this point in the history
Refactored symlink resolution to filter out of the final `includedPaths` list of files
  • Loading branch information
BobaFetters committed May 4, 2023
1 parent 9a98154 commit 05b9e89
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions Sources/ApolloCodegenLib/Glob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,10 @@ public struct Glob {
}
}

// Resolve symlinks in any included paths
includeMatches = includeMatches.compactMap({ path in
return URL(fileURLWithPath: path).resolvingSymlinksInPath().path
})
return OrderedSet<String>(includeMatches).subtracting(excludeMatches)
}

Expand Down Expand Up @@ -125,10 +129,7 @@ public struct Glob {
let isExclude = pattern.isExclude
var parts = pattern.components(separatedBy: String.Globstar)
var firstPart = parts.removeFirst()
let last = parts.joined(separator: String.Globstar)
parts = last.components(separatedBy: "*")
let lastDirComponent = parts.removeFirst()
let lastPart = "*\(parts.joined(separator: "*"))"
let lastPart = parts.joined(separator: String.Globstar)

if isExclude {
// Remove ! here otherwise the Linux glob function would not return any results. Results for
Expand Down Expand Up @@ -188,9 +189,7 @@ public struct Glob {
}

return OrderedSet<String>(directories.compactMap({ directory in
// build directory URL up to the first '*' in the pattern, and resolve symlinks
let url = directory.appendingPathComponent(lastDirComponent).standardizedFileURL.resolvingSymlinksInPath()
var path = url.appendingPathComponent("\(lastPart)").standardizedFileURL.path
var path = directory.appendingPathComponent(lastPart).standardizedFileURL.path
if isExclude {
path.insert("!", at: path.startIndex)
}
Expand Down

0 comments on commit 05b9e89

Please sign in to comment.