Run a virtual iPhone on an Apple Silicon Mac.
Swift
Mark the guest environment unknown after reverting to an unsaved snapshot
Jacky680b3a0d2730
diff --git a/VPhoneLaunchpad/Tests/MachineSnapshotsTests.swift b/VPhoneLaunchpad/Tests/MachineSnapshotsTests.swiftindex d6e4f729..5dab0151 100644--- a/VPhoneLaunchpad/Tests/MachineSnapshotsTests.swift+++ b/VPhoneLaunchpad/Tests/MachineSnapshotsTests.swift@@ -114,10 +114,21 @@ struct MachineSnapshotsTests {// A snapshot from before Launchpad knew the guest environment leaves it unknown.precondition(current.reverted(to: VPhoneLaunchpadMachineBinding(bundle: "2.7.0")).guestEnvironment == nil,"An unknown guest environment stays unknown")+ // A snapshot with no saved binding (taken with vphone-cli, or the+ // copy was not written) makes both unknown rather than keeping the+ // newer ones the revert just replaced; the bundle stays.+ let unsaved = current.reverted(to: nil)+ precondition(unsaved == VPhoneLaunchpadMachineBinding(bundle: "2.7.1-local.ab12cd34"), "Reverted without a saved binding: \(unsaved)")+ precondition(!unsaved.hasMixedVersions, "An unknown guest environment is not claimed to match or differ")+ precondition(VPhoneLaunchpadMachineBinding.load(machine, snapshot: "missing") == nil, "A snapshot with no folder has no saved binding")+ precondition(current.reverted(to: VPhoneLaunchpadMachineBinding.load(machine, snapshot: "fresh")) == reverted,+ "A readable saved binding still supplies the boot chain and guest environment")// The sidecar is checked like the machine's own binding.try Data(#"{"bundle":"2.7.0","guestEnvironment":"../evil"}"#.utf8).write(to: sidecar)precondition(VPhoneLaunchpadMachineBinding.load(machine, snapshot: "fresh") == nil, "An invalid sidecar is rejected")+ precondition(current.reverted(to: VPhoneLaunchpadMachineBinding.load(machine, snapshot: "fresh")) == unsaved,+ "An unreadable saved binding counts as none")// Names outside the rules, and folders that are links, are refused.for name in ["", ".", "..", "../research-02", "a/b", ".hidden"] {diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineBinding.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineBinding.swiftindex f4b2b6f0..4794e660 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineBinding.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineBinding.swift@@ -20,10 +20,11 @@ nonisolated struct VPhoneLaunchpadMachineBinding: Codable, Equatable, Sendable {/// The store version every command on this machine runs with.var bundle: String/// The bundle that patched and restored the boot chain. Nil for a- /// machine created before Launchpad recorded it.+ /// machine created before Launchpad recorded it, or reverted to a+ /// snapshot Launchpad saved no binding with.var bootChain: String?/// The bundle whose guest environment was installed last. Nil while- /// unknown.+ /// unknown, as after a revert to a snapshot with no saved binding.var guestEnvironment: String?static let fileName = "launchpad.json"@@ -120,16 +121,19 @@ nonisolated struct VPhoneLaunchpadMachineBinding: Codable, Equatable, Sendable {try write(to: url)}- /// This binding after its machine is reverted to a snapshot taken with- /// `snapshot` as the binding. The guest environment and the boot chain- /// live on the disk and in the NVRAM the revert put back, so they are- /// whatever they were when the snapshot was taken. The host programs are- /// not part of the machine's files: the bundle stays the one chosen now.- func reverted(to snapshot: VPhoneLaunchpadMachineBinding) -> VPhoneLaunchpadMachineBinding {+ /// This binding after its machine is reverted to a snapshot, given the+ /// binding saved with it. The guest environment and the boot chain live+ /// on the disk and in the NVRAM the revert put back, so they are+ /// whatever they were when the snapshot was taken: the saved ones, or+ /// unknown when nothing readable was saved (a snapshot taken with+ /// vphone-cli), never the ones the machine had before the revert. The+ /// host programs are not part of the machine's files: the bundle stays+ /// the one chosen now.+ func reverted(to saved: VPhoneLaunchpadMachineBinding?) -> VPhoneLaunchpadMachineBinding {VPhoneLaunchpadMachineBinding(bundle: bundle,- bootChain: snapshot.bootChain,- guestEnvironment: snapshot.guestEnvironment,+ bootChain: saved?.bootChain,+ guestEnvironment: saved?.guestEnvironment,)}}diff --git a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swiftindex 2b83e7df..a5b3e61d 100644--- a/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift+++ b/VPhoneLaunchpad/VPhoneLaunchpad/Machines/VPhoneLaunchpadMachineLibrary.swift@@ -849,8 +849,8 @@ final class VPhoneLaunchpadMachineLibrary {on: machine,machine.snapshotCreateArguments(name, note: note),)- // The snapshot is taken either way; without the copy a revert only- // leaves the binding as it is then.+ // The snapshot is taken either way; without the copy a revert can+ // only mark the guest environment and boot chain unknown.if let binding = currentBinding(of: machine) {try? binding.save(to: machine, snapshot: name)}@@ -866,11 +866,12 @@ final class VPhoneLaunchpadMachineLibrary {)// The guest environment and the boot chain are on the disk and in// the NVRAM the revert just replaced, so the binding takes them from- // the copy saved with the snapshot. The bundle is not on the disk:- // the machine keeps running with the one chosen now.- if let saved = VPhoneLaunchpadMachineBinding.load(machine, snapshot: name),- let current = currentBinding(of: machine)- {+ // the copy saved with the snapshot, or become unknown when there is+ // none to read (a snapshot taken with vphone-cli, or a copy that was+ // not written). The bundle is not on the disk: the machine keeps+ // running with the one chosen now.+ if let current = currentBinding(of: machine) {+ let saved = VPhoneLaunchpadMachineBinding.load(machine, snapshot: name)try? bind(machine, current.reverted(to: saved))}}