This commit is contained in:
Max Howell
2019-01-17 16:33:38 -05:00
parent 8e0d766924
commit 97e9cbaa8f
16 changed files with 754 additions and 0 deletions

View File

@@ -0,0 +1,21 @@
import Foundation
public class TemporaryDirectory {
public let url: URL
public var path: Path { return Path(string: url.path) }
public init() throws {
url = try FileManager.default.url(for: .itemReplacementDirectory, in: .userDomainMask, appropriateFor: URL(fileURLWithPath: "/"), create: true)
}
deinit {
_ = try? FileManager.default.removeItem(at: url)
}
}
public extension Path {
static func mktemp<T>(body: (Path) throws -> T) throws -> T {
let tmp = try TemporaryDirectory()
return try body(tmp.path)
}
}