Compare commits
3 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c9d300a7b6 | ||
|
|
ed4b773870 | ||
|
|
097e020735 |
@@ -181,7 +181,7 @@ with your work without worries.
|
||||
There is also some magic going on in Foundation’s filesystem APIs, which we look
|
||||
for and ensure our API is deterministic, eg. [this test].
|
||||
|
||||
[this test]: TODO
|
||||
[this test]: https://github.com/mxcl/Path.swift/blob/master/Tests/PathTests/PathTests.swift#L539-L554
|
||||
|
||||
# `Path.swift` is properly cross-platform
|
||||
|
||||
@@ -281,7 +281,7 @@ Therefore, if you are not using this feature you are fine. If you have URLs the
|
||||
way to get a `Path` is:
|
||||
|
||||
```swift
|
||||
if let path = Path(url) {
|
||||
if let path = Path(url: url) {
|
||||
/*…*/
|
||||
}
|
||||
```
|
||||
|
||||
@@ -78,11 +78,7 @@ public struct Path: Equatable, Hashable, Comparable {
|
||||
tilded = dir
|
||||
}
|
||||
#else
|
||||
if username != NSUserName() {
|
||||
return nil
|
||||
} else {
|
||||
tilded = NSHomeDirectory()
|
||||
}
|
||||
return nil // there are no usernames on iOS, etc.
|
||||
#endif
|
||||
}
|
||||
pathComponents.remove(at: 0)
|
||||
@@ -108,13 +104,22 @@ public struct Path: Equatable, Hashable, Comparable {
|
||||
self.string = join_(prefix: "/", pathComponents: pathComponents)
|
||||
}
|
||||
|
||||
public init?(_ url: URL) {
|
||||
/**
|
||||
Creates a new absolute, standardized path from the provided file-scheme URL.
|
||||
- Note: If the URL is not a file URL, returns `nil`.
|
||||
*/
|
||||
public init?(url: URL) {
|
||||
guard url.scheme == "file" else { return nil }
|
||||
self.init(string: url.path)
|
||||
self.init(url.path)
|
||||
//NOTE: URL cannot be a file-reference url, unlike NSURL, so this always works
|
||||
}
|
||||
|
||||
public init?(_ url: NSURL) {
|
||||
/**
|
||||
Creates a new absolute, standardized path from the provided file-scheme URL.
|
||||
- Note: If the URL is not a file URL, returns `nil`.
|
||||
- Note: If the URL is a file reference URL, converts it to a POSIX path first.
|
||||
*/
|
||||
public init?(url: NSURL) {
|
||||
guard url.scheme == "file", let path = url.path else { return nil }
|
||||
self.init(string: path)
|
||||
// ^^ works even if the url is a file-reference url
|
||||
|
||||
@@ -577,10 +577,10 @@ class PathTests: XCTestCase {
|
||||
}
|
||||
|
||||
func testURLInitializer() throws {
|
||||
XCTAssertEqual(Path(Path.home.url), Path.home)
|
||||
XCTAssertEqual(Path(url: Path.home.url), Path.home)
|
||||
XCTAssertEqual(Path.home.fileReferenceURL.flatMap(Path.init), Path.home)
|
||||
XCTAssertNil(Path(URL(string: "https://foo.com")!))
|
||||
XCTAssertNil(Path(NSURL(string: "https://foo.com")!))
|
||||
XCTAssertNil(Path(url: URL(string: "https://foo.com")!))
|
||||
XCTAssertNil(Path(url: NSURL(string: "https://foo.com")!))
|
||||
}
|
||||
|
||||
func testInitializerForRelativePath() throws {
|
||||
|
||||
Reference in New Issue
Block a user