From 9a981542404506ba9c8d35b99645b68797ea42b2 Mon Sep 17 00:00:00 2001 From: Zach FettersMoore <4425109+BobaFetters@users.noreply.github.com> Date: Thu, 4 May 2023 09:19:18 -0400 Subject: [PATCH] Refactoring symlink check Refactoring the symlink check so that the same code handles both production and test use cases instead of needing 2 different pieces of code. --- Sources/ApolloCodegenLib/Glob.swift | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) diff --git a/Sources/ApolloCodegenLib/Glob.swift b/Sources/ApolloCodegenLib/Glob.swift index 3d90c60468..0f6dcfdc64 100644 --- a/Sources/ApolloCodegenLib/Glob.swift +++ b/Sources/ApolloCodegenLib/Glob.swift @@ -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 @@ -186,15 +188,9 @@ public struct Glob { } return OrderedSet(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) }