-
Notifications
You must be signed in to change notification settings - Fork 119
Expand file tree
/
Copy pathDisposableVMWorkspace.swift
More file actions
30 lines (27 loc) · 1.07 KB
/
Copy pathDisposableVMWorkspace.swift
File metadata and controls
30 lines (27 loc) · 1.07 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import Foundation
/// One disk per app session, including any settings-driven QEMU restarts.
/// The normal storage backend owns locking and disk validation inside it.
final class DisposableVMWorkspace {
private(set) var directory: URL?
func prepare() throws -> URL {
if let directory { return directory }
let directory = FileManager.default.temporaryDirectory
.appendingPathComponent("try-omarchy-disposable-\(UUID().uuidString)", isDirectory: true)
try FileManager.default.createDirectory(
at: directory, withIntermediateDirectories: false,
attributes: [.posixPermissions: 0o700]
)
self.directory = directory
return directory
}
/// Call only after the launcher and QEMU have exited.
func remove() {
guard let directory else { return }
do {
try FileManager.default.removeItem(at: directory)
self.directory = nil
} catch {
fputs("[storage] could not remove disposable VM: \(error.localizedDescription)\n", stderr)
}
}
}