Fix iOS, etc.

This commit is contained in:
Max Howell
2019-02-11 14:19:27 -05:00
parent 709c3fb99d
commit 164cd2b413
2 changed files with 11 additions and 1 deletions

View File

@@ -68,7 +68,7 @@ public struct Path: Equatable, Hashable, Comparable {
tilded = Path.home.string
} else {
let username = String(pathComponents[0].dropFirst())
#if os(macOS) || os(Linux)
if #available(OSX 10.12, *) {
guard let url = FileManager.default.homeDirectory(forUser: username) else { return nil }
assert(url.scheme == "file")
@@ -77,6 +77,13 @@ public struct Path: Equatable, Hashable, Comparable {
guard let dir = NSHomeDirectoryForUser(username) else { return nil }
tilded = dir
}
#else
if username != NSUserName() {
return nil
} else {
tilded = NSHomeDirectory()
}
#endif
}
pathComponents.remove(at: 0)
pathComponents.insert(contentsOf: tilded.split(separator: "/"), at: 0)

View File

@@ -493,6 +493,8 @@ class PathTests: XCTestCase {
}
func testReadlinkOnRelativeSymlink() throws {
//TODO how to test on iOS etc.?
#if os(macOS) || os(Linux)
try Path.mktemp { tmpdir in
let foo = try tmpdir.foo.mkdir()
let bar = try tmpdir.bar.touch()
@@ -511,6 +513,7 @@ class PathTests: XCTestCase {
XCTAssertEqual(try tmpdir.foo.baz.readlink(), bar)
}
#endif
}
func testReadlinkOnFileReturnsSelf() throws {