mxcl / Path.swift

Delightful, robust, cross-platform and chainable file-pathing functions.
The Unlicense
946 stars 36 forks source link

Added wrapper around temporary directory #60

Closed acecilia closed 4 years ago

mxcl commented 4 years ago

https://developer.apple.com/documentation/foundation/1409211-nstemporarydirectory

Discussion

See the FileManager method url(for:in:appropriateFor:create:) for the preferred means of finding the correct temporary directory.

So, really, we should not offer this.

acecilia commented 4 years ago

PathKit is doing the same: https://github.com/kylef/PathKit/blob/c8f12353bca8c252713fd2e2fbc5789c39ff92f8/Sources/PathKit.swift#L475

Do you prefer the following alternative, as explained by the docs you linked?:

    let temporaryDirectory = try FileManager.default.url(
        for: .itemReplacementDirectory,
        in: .userDomainMask,
        appropriateFor: URL(fileURLWithPath: "/"),
        create: true
    )
mxcl commented 4 years ago

Apple are pretty clear that:

appropriateFor: URL(fileURLWithPath: "/")

Is not acceptable. The only way we should add this would be to make it a function that accepts a path so as to determine the URL correctly. This is certainly not as elegant, but I do not want to encourage people to use this library in a way that opens them up to unexpected issues.