Skip to content

Basic: replace resolvingSymlinks with Foundation #52

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 4 additions & 17 deletions Sources/TSCBasic/PathShims.swift
Original file line number Diff line number Diff line change
Expand Up @@ -22,24 +22,11 @@ import Foundation

/// Returns the "real path" corresponding to `path` by resolving any symbolic links.
public func resolveSymlinks(_ path: AbsolutePath) -> AbsolutePath {
let pathStr = path.pathString

// FIXME: We can't use FileManager's destinationOfSymbolicLink because
// that implements readlink and not realpath.
if let resultPtr = TSCLibc.realpath(pathStr, nil) {
let result = String(cString: resultPtr)
// If `resolved_path` is specified as NULL, then `realpath` uses
// malloc(3) to allocate a buffer [...]. The caller should deallocate
// this buffer using free(3).
//
// String.init(cString:) creates a new string by copying the
// null-terminated UTF-8 data referenced by the given pointer.
resultPtr.deallocate()
// FIXME: We should measure if it's really more efficient to compare the strings first.
return result == pathStr ? path : AbsolutePath(result)
do {
return try AbsolutePath(FileManager.default.destinationOfSymbolicLink(atPath: path.pathString).standardizingPath)
} catch {
return AbsolutePath(path.pathString.standardizingPath)
}

return path
}

/// Creates a new, empty directory at `path`. If needed, any non-existent ancestor paths are also created. If there is
Expand Down
8 changes: 0 additions & 8 deletions Sources/TSCLibc/libc.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,6 @@
@_exported import TSCclibc

#if os(Windows)
// char *realpath(const char *path, char *resolved_path);
public func realpath(
_ path: String,
_ resolvedPath: UnsafeMutablePointer<CChar>?
) -> UnsafeMutablePointer<CChar>? {
fatalError("realpath is unimplemented")
}

// char *mkdtemp(char *template);
public func mkdtemp(
_ template: UnsafeMutablePointer<CChar>?
Expand Down