/// An interrupted extension may leave files. Only this feature's private
5
/// invocation directories are swept, after its maximum request lifetime.
6
public static func begin(root: URL = FileManager.default.temporaryDirectory, now: Date = Date()) throws -> URL {
7
let prefix = "equipo-share-stage-"
8
for url in (try? FileManager.default.contentsOfDirectory(at: root, includingPropertiesForKeys: [.creationDateKey])) ?? [] where url.lastPathComponent.hasPrefix(prefix) {
9
if let created = try? url.resourceValues(forKeys: [.creationDateKey]).creationDate, now.timeIntervalSince(created) > 15 * 60 {
10
try? FileManager.default.removeItem(at: url)
11
}
12
}
13
let directory = root.appendingPathComponent(prefix + UUID().uuidString)