in Sources/TSCBasic/Path.swift [801:838]
func appending(relativePath: UNIXPath) -> UNIXPath {
#if os(Windows)
var result: PWSTR?
_ = string.withCString(encodedAs: UTF16.self) { root in
relativePath.string.withCString(encodedAs: UTF16.self) { path in
PathAllocCombine(root, path, ULONG(PATHCCH_ALLOW_LONG_PATHS.rawValue), &result)
}
}
defer { LocalFree(result) }
return PathImpl(string: String(decodingCString: result!, as: UTF16.self))
#else
// Both paths are already normalized. The only case in which we have
// to renormalize their concatenation is if the relative path starts
// with a `..` path component.
var newPathString = string
if self != .root {
newPathString.append("/")
}
let relativePathString = relativePath.string
newPathString.append(relativePathString)
// If the relative string starts with `.` or `..`, we need to normalize
// the resulting string.
// FIXME: We can actually optimize that case, since we know that the
// normalization of a relative path can leave `..` path components at
// the beginning of the path only.
if relativePathString.hasPrefix(".") {
if newPathString.hasPrefix("/") {
return PathImpl(normalizingAbsolutePath: newPathString)
} else {
return PathImpl(normalizingRelativePath: newPathString)
}
} else {
return PathImpl(string: newPathString)
}
#endif
}