Skip to content

Commit

Permalink
Refactoring symlink check
Browse files Browse the repository at this point in the history
Refactoring the symlink check so that the same code handles both production and test use cases instead of needing 2 different pieces of code.
  • Loading branch information
BobaFetters committed May 4, 2023
1 parent fa6d427 commit 9a98154
Showing 1 changed file with 7 additions and 11 deletions.
18 changes: 7 additions & 11 deletions Sources/ApolloCodegenLib/Glob.swift
Original file line number Diff line number Diff line change
Expand Up @@ -125,8 +125,10 @@ public struct Glob {
let isExclude = pattern.isExclude
var parts = pattern.components(separatedBy: String.Globstar)
var firstPart = parts.removeFirst()
let lastPart = parts.joined(separator: String.Globstar)
let lastDirComponent = lastPart.components(separatedBy: "*").first ?? ""
let last = parts.joined(separator: String.Globstar)
parts = last.components(separatedBy: "*")
let lastDirComponent = parts.removeFirst()
let lastPart = "*\(parts.joined(separator: "*"))"

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

return OrderedSet<String>(directories.compactMap({ directory in
// build directory URL up the the '*' in the pattern, and check if it is a symlink, if so skip it
let symCheckURL = directory.appendingPathComponent(lastDirComponent).standardizedFileURL
if let resourceValues = try? symCheckURL.resourceValues(forKeys: [.isSymbolicLinkKey]),
let isSymLink = resourceValues.isSymbolicLink,
isSymLink {
return nil
}

var path = directory.resolvingSymlinksInPath().appendingPathComponent(lastPart).standardizedFileURL.path
// 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
if isExclude {
path.insert("!", at: path.startIndex)
}
Expand Down

0 comments on commit 9a98154

Please sign in to comment.