From cbce7e668e75f3bd5fbc53a7872a57e0b5edcce8 Mon Sep 17 00:00:00 2001 From: Guilherme Rambo Date: Fri, 29 Sep 2023 00:28:27 -0300 Subject: [PATCH] Always using default library directory for guest image, failing gracefully when guest image is missing --- VirtualBuddy/Config/Versions.xcconfig | 4 ++-- .../GuestAdditionsDiskImage.swift | 21 ++++++------------- ...cOSVirtualMachineConfigurationHelper.swift | 5 ++--- 3 files changed, 10 insertions(+), 20 deletions(-) diff --git a/VirtualBuddy/Config/Versions.xcconfig b/VirtualBuddy/Config/Versions.xcconfig index 96148b00..031627a3 100644 --- a/VirtualBuddy/Config/Versions.xcconfig +++ b/VirtualBuddy/Config/Versions.xcconfig @@ -1,4 +1,4 @@ -MARKETING_VERSION = 1.3 -CURRENT_PROJECT_VERSION = 104 +MARKETING_VERSION = 1.3.1 +CURRENT_PROJECT_VERSION = 105 DYLIB_CURRENT_VERSION = $(CURRENT_PROJECT_VERSION) VERSIONING_SYSTEM = apple-generic diff --git a/VirtualCore/Source/GuestSupport/GuestAdditionsDiskImage.swift b/VirtualCore/Source/GuestSupport/GuestAdditionsDiskImage.swift index 6d2675e5..f2cea045 100644 --- a/VirtualCore/Source/GuestSupport/GuestAdditionsDiskImage.swift +++ b/VirtualCore/Source/GuestSupport/GuestAdditionsDiskImage.swift @@ -70,19 +70,9 @@ public final class GuestAdditionsDiskImage { } } - private let imageNameSuffix: String = { - #if DEBUG - return "-DEBUG" - #else - return "" - #endif - }() - - private var imageName: String { "VirtualBuddyGuest\(imageNameSuffix)" } + private var imageName: String { "VirtualBuddyGuest" } - private var libraryURL: URL { VBSettingsContainer.current.settings.libraryURL } - - private var imagesRootURL: URL { libraryURL.appendingPathComponent("_GuestImage") } + private var imagesRootURL: URL { URL.defaultVirtualBuddyLibraryURL.appendingPathComponent("_GuestImage") } private var installedImageDigestURL: URL { imagesRootURL @@ -159,8 +149,7 @@ public final class GuestAdditionsDiskImage { p.arguments = [ scriptPath, guestPath, - digest, - imageNameSuffix + digest ] let outPipe = Pipe() let errPipe = Pipe() @@ -201,10 +190,12 @@ public final class GuestAdditionsDiskImage { extension VZVirtioBlockDeviceConfiguration { - static var guestAdditionsDisk: VZVirtioBlockDeviceConfiguration { + static var guestAdditionsDisk: VZVirtioBlockDeviceConfiguration? { get throws { let guestImageURL = GuestAdditionsDiskImage.current.installedImageURL + guard FileManager.default.fileExists(atPath: guestImageURL.path) else { return nil } + let guestAttachment = try VZDiskImageStorageDeviceAttachment(url: guestImageURL, readOnly: true) return VZVirtioBlockDeviceConfiguration(attachment: guestAttachment) diff --git a/VirtualCore/Source/Virtualization/Helpers/MacOSVirtualMachineConfigurationHelper.swift b/VirtualCore/Source/Virtualization/Helpers/MacOSVirtualMachineConfigurationHelper.swift index 1c37e631..5406d49d 100644 --- a/VirtualCore/Source/Virtualization/Helpers/MacOSVirtualMachineConfigurationHelper.swift +++ b/VirtualCore/Source/Virtualization/Helpers/MacOSVirtualMachineConfigurationHelper.swift @@ -30,9 +30,8 @@ struct MacOSVirtualMachineConfigurationHelper: VirtualMachineConfigurationHelper func createAdditionalBlockDevices() async throws -> [VZVirtioBlockDeviceConfiguration] { var devices = try vm.additionalBlockDevices - if vm.configuration.guestAdditionsEnabled { - let guestDisk = try VZVirtioBlockDeviceConfiguration.guestAdditionsDisk - devices.append(guestDisk) + if vm.configuration.guestAdditionsEnabled, let disk = try? VZVirtioBlockDeviceConfiguration.guestAdditionsDisk { + devices.append(disk) } return devices