Cleanup temporary URLs

This commit is contained in:
Nindi Gill 2022-12-23 15:36:55 +11:00
parent 011859c993
commit c92843822f
No known key found for this signature in database
GPG key ID: FF9A7FD590D4F4B1
2 changed files with 16 additions and 10 deletions

View file

@ -150,7 +150,6 @@ class TaskManager: ObservableObject {
var taskGroups: [(section: MistTaskSection, tasks: [MistTask])] = [] var taskGroups: [(section: MistTaskSection, tasks: [MistTask])] = []
let cacheDirectoryURL: URL = URL(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id) let cacheDirectoryURL: URL = URL(fileURLWithPath: cacheDirectory).appendingPathComponent(installer.id)
let temporaryDirectoryURL: URL = URL(fileURLWithPath: .temporaryDirectory) let temporaryDirectoryURL: URL = URL(fileURLWithPath: .temporaryDirectory)
let mountPointURL: URL = URL(fileURLWithPath: "/Volumes/\(installer.id) Temp")
guard let destinationURL: URL = destinationURL else { guard let destinationURL: URL = destinationURL else {
throw MistError.invalidDestinationURL throw MistError.invalidDestinationURL
@ -167,7 +166,7 @@ class TaskManager: ObservableObject {
taskGroups += [ taskGroups += [
( (
section: .setup, section: .setup,
tasks: installTasks(for: installer, temporaryDirectory: temporaryDirectoryURL, mountPoint: mountPointURL, cacheDirectory: cacheDirectory) tasks: installTasks(for: installer, temporaryDirectory: temporaryDirectoryURL, mountPoint: installer.temporaryDiskImageMountPointURL, cacheDirectory: cacheDirectory)
) )
] ]
} }
@ -214,7 +213,12 @@ class TaskManager: ObservableObject {
taskGroups += [ taskGroups += [
( (
section: .cleanup, section: .cleanup,
tasks: cleanupTasks(mountPoint: mountPointURL, temporaryDirectory: temporaryDirectoryURL, cacheDownloads: cacheDownloads, cacheDirectory: cacheDirectoryURL) tasks: cleanupTasks(
mountPoint: installer.temporaryDiskImageMountPointURL,
temporaryDirectory: temporaryDirectoryURL,
cacheDownloads: cacheDownloads,
cacheDirectory: cacheDirectoryURL
)
) )
] ]
} }
@ -276,7 +280,6 @@ class TaskManager: ObservableObject {
private static func installTasks(for installer: Installer, temporaryDirectory temporaryDirectoryURL: URL, mountPoint mountPointURL: URL, cacheDirectory: String) -> [MistTask] { private static func installTasks(for installer: Installer, temporaryDirectory temporaryDirectoryURL: URL, mountPoint mountPointURL: URL, cacheDirectory: String) -> [MistTask] {
let imageURL: URL = temporaryDirectoryURL.appendingPathComponent("\(installer.id) Temp.dmg") let imageURL: URL = temporaryDirectoryURL.appendingPathComponent("\(installer.id) Temp.dmg")
let mountPointURL: URL = URL(fileURLWithPath: "/Volumes/\(installer.id) Temp")
return [ return [
MistTask(type: .configure, description: "temporary directory") { MistTask(type: .configure, description: "temporary directory") {
@ -362,13 +365,13 @@ class TaskManager: ObservableObject {
try await DiskImageCreator.create(temporaryImageURL, size: installer.isoSize) try await DiskImageCreator.create(temporaryImageURL, size: installer.isoSize)
}, },
MistTask(type: .mount, description: "temporary Disk Image") { MistTask(type: .mount, description: "temporary Disk Image") {
try await DiskImageMounter.mount(temporaryImageURL, mountPoint: installer.temporaryMountPointURL) try await DiskImageMounter.mount(temporaryImageURL, mountPoint: installer.temporaryISOMountPointURL)
}, },
MistTask(type: .create, description: "macOS Installer in temporary Disk Image") { MistTask(type: .create, description: "macOS Installer in temporary Disk Image") {
try await InstallMediaCreator.create(createInstallMediaURL, mountPoint: installer.temporaryMountPointURL) try await InstallMediaCreator.create(createInstallMediaURL, mountPoint: installer.temporaryISOMountPointURL)
}, },
MistTask(type: .unmount, description: "temporary Disk Image") { MistTask(type: .unmount, description: "temporary Disk Image") {
try await DiskImageUnmounter.unmount(installer.temporaryMountPointURL) try await DiskImageUnmounter.unmount(installer.temporaryISOMountPointURL)
}, },
MistTask(type: .convert, description: "temporary Disk Image to ISO") { MistTask(type: .convert, description: "temporary Disk Image to ISO") {
try await ISOConverter.convert(temporaryImageURL, destination: temporaryCDRURL) try await ISOConverter.convert(temporaryImageURL, destination: temporaryCDRURL)

View file

@ -227,11 +227,14 @@ struct Installer: Decodable, Hashable, Identifiable {
var allDownloads: [Package] { var allDownloads: [Package] {
[Package(url: distributionURL, size: distributionSize, integrityDataURL: nil, integrityDataSize: nil)] + packages.sorted { $0.filename < $1.filename } [Package(url: distributionURL, size: distributionSize, integrityDataURL: nil, integrityDataSize: nil)] + packages.sorted { $0.filename < $1.filename }
} }
var temporaryMountPointURL: URL { var temporaryDiskImageMountPointURL: URL {
URL(fileURLWithPath: "/Volumes/Install \(name)") URL(fileURLWithPath: "/Volumes/\(id) Temp")
} }
var temporaryInstallerURL: URL { var temporaryInstallerURL: URL {
URL(fileURLWithPath: "/Volumes/\(id) Temp/Applications/Install \(name).app") temporaryDiskImageMountPointURL.appendingPathComponent("/Applications/Install \(name).app")
}
var temporaryISOMountPointURL: URL {
URL(fileURLWithPath: "/Volumes/\(id)")
} }
var dictionary: [String: Any] { var dictionary: [String: Any] {
[ [