.some
This commit is contained in:
21
Sources/TemporaryDirectory.swift
Normal file
21
Sources/TemporaryDirectory.swift
Normal 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)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user