diff --git a/CHANGELOG.md b/CHANGELOG.md index 6050c51d..29ef078b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ [John Fairhurst](https://github.com/johnfairh) * Improve reporting of `sourcekitdInProc` loading failures. [Daniel Sunarjo](https://github.com/sunarjodaniel) +* Avoid `getcwd` in `absolutePathRepresentation()` for absolute paths. + [Brett Best](https://github.com/Brett-Best) #### Bug Fixes diff --git a/Source/SourceKittenFramework/String+SourceKitten.swift b/Source/SourceKittenFramework/String+SourceKitten.swift index e13e2b49..eb18c047 100644 --- a/Source/SourceKittenFramework/String+SourceKitten.swift +++ b/Source/SourceKittenFramework/String+SourceKitten.swift @@ -170,9 +170,12 @@ extension NSString { Returns self represented as an absolute path. - parameter rootDirectory: Absolute parent path if not already an absolute path. + Uses the current directory by default, evaluated only + if this path is relative. */ - public func absolutePathRepresentation(rootDirectory: String = FileManager.default.currentDirectoryPath) -> String { + public func absolutePathRepresentation(rootDirectory: String? = nil) -> String { if isAbsolutePath { return expandingTildeInPath } + let rootDirectory = rootDirectory ?? FileManager.default.currentDirectoryPath #if os(Linux) return NSURL(fileURLWithPath: NSURL.fileURL(withPathComponents: [rootDirectory, bridge()])!.path).standardizingPath!.path #else