Tests/OrgWorkspaceTests/Folder.swift

58136891cdc8257199ae9055a2432e82f81ea7ea
orgstar/Tests/OrgWorkspaceTests/Folder.swift

23 lines · 773 bytes

 1import Foundation
 2
 3/// A temporary folder that removes itself.
 4final class Folder {
 5    let url: URL
 6
 7    init() throws {
 8        url = FileManager.default.temporaryDirectory.appendingPathComponent("orgstar-\(UUID().uuidString)").standardizedFileURL
 9        try FileManager.default.createDirectory(at: url, withIntermediateDirectories: true)
10    }
11
12    deinit {
13        try? FileManager.default.removeItem(at: url)
14    }
15
16    @discardableResult
17    func write(_ path: String, _ text: String) throws -> URL {
18        let file = url.appendingPathComponent(path)
19        try FileManager.default.createDirectory(at: file.deletingLastPathComponent(), withIntermediateDirectories: true)
20        try Data(text.utf8).write(to: file)
21        return file.standardizedFileURL
22    }
23}
Keyboard shortcuts

Global

⌘K
Command palette & jump
/
Focus search
?
Show this help
g d
Dashboard
g e
Explore repositories
g n
Notifications

Repository & editor

t
Find file in repository
y
Copy immutable SHA permalink
g c
Code tab
g i
Issues tab
g m
Merge requests tab
g b
Builds tab
⌘↵
Submit active form