Skip to content

Commit ab6470b

Browse files
committed
Basic: use .resolvingSymlinksInPath instead of realpath
This Foundation extension provides the same behaviour but is portable across different platforms.
1 parent d8e2743 commit ab6470b

File tree

1 file changed

+1
-12
lines changed

1 file changed

+1
-12
lines changed

Sources/Basic/PathShims.swift

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,11 @@
1717
while making it fairly easy to find those calls later.
1818
*/
1919

20-
import SPMLibc
2120
import Foundation
2221

2322
/// Returns the "real path" corresponding to `path` by resolving any symbolic links.
2423
public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
25-
let pathStr = path.pathString
26-
27-
// FIXME: We can't use FileManager's destinationOfSymbolicLink because
28-
// that implements readlink and not realpath.
29-
if let resultPtr = SPMLibc.realpath(pathStr, nil) {
30-
let result = String(cString: resultPtr)
31-
// FIXME: We should measure if it's really more efficient to compare the strings first.
32-
return result == pathStr ? path : AbsolutePath(result)
33-
}
34-
35-
return path
24+
return AbsolutePath(path.pathString.resolvingSymlinksInPath)
3625
}
3726

3827
/// Creates a new, empty directory at `path`. If needed, any non-existent ancestor paths are also created. If there is

0 commit comments

Comments
 (0)