oficina / equipo Public

Clone
git clone https://amadan.net/oficina/equipo

Plain git — no account needed to clone.

Download

Download this file

1import Foundation
2
3public enum ShareStaging {
4 /// 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)
14 try FileManager.default.createDirectory(at: directory, withIntermediateDirectories: true, attributes: [.posixPermissions: 0o700])
15 return directory
16 }
17}
18