@@ -79,18 +79,26 @@ struct Prepare: ParsableCommand {
7979 os_log ( " The base VMware Fusion guest is %{public}@ " , log: log, type: . debug, baseVMPath. string)
8080 let base = VirtualMachine ( image: baseVMPath, executable: options. vmwareFusion)
8181
82- /// The name of VMware Fusion guest created by the clone operation
83- let clonedGuestName = " \( base. name) -runner- \( ciRunnerId) -concurrent- \( ciConcurrentProjectId) "
82+ // Check if the snapshot exists (creating it if necessary)
83+ let rootSnapshotname = subsystem
84+ if !base. snapshots. contains ( rootSnapshotname) {
85+ FileHandle . standardOutput
86+ . write ( line: " Creating snapshot \" \( rootSnapshotname) \" in base guest \" \( base. name) \" ... " )
87+ try base. snapshot ( rootSnapshotname)
88+ }
8489
8590 // Check if the snapshot exists (creating it if necessary)
86- let baseVMSnapshotName = " base-snapshot -\( clonedGuestName ) "
87- if !base. snapshots. contains ( baseVMSnapshotName ) {
91+ let cloneBaseSnapshotname = " \( ciServerHost ) -runner -\( ciRunnerId ) -concurrent- \( ciConcurrentProjectId ) "
92+ if !base. snapshots. contains ( cloneBaseSnapshotname ) {
8893 FileHandle . standardOutput
89- . write ( line: " Creating snapshot \" \( baseVMSnapshotName) \" in base guest \" \( base. name) \" ... " )
90- try base. snapshot ( baseVMSnapshotName)
94+ . write ( line: " Creating snapshot \" \( cloneBaseSnapshotname) \" in base guest \" \( base. name) \" ... " )
95+ // Ensure that the common base snapshot is used
96+ try base. revert ( to: rootSnapshotname)
97+ try base. snapshot ( cloneBaseSnapshotname)
9198 }
9299
93100 /// The path of the VMware Fusion guest created by the clone operation
101+ let clonedGuestName = " \( base. name) - \( ciServerHost) -runner- \( ciRunnerId) -concurrent- \( ciConcurrentProjectId) "
94102 let clonedGuestPath = options. vmImagesPath
95103 . join ( " \( clonedGuestName) .vmwarevm " )
96104 . join ( " \( clonedGuestName) .vmx " )
@@ -99,8 +107,8 @@ struct Prepare: ParsableCommand {
99107 let clone : VirtualMachine
100108 if !clonedGuestPath. exists {
101109 FileHandle . standardOutput
102- . write ( line: " Cloning from snapshot \" \( baseVMSnapshotName ) \" in base guest \" \( base. name) \" to \" \( clonedGuestName) \" ... " )
103- clone = try base. clone ( to: clonedGuestPath, named: clonedGuestName, linkedTo: baseVMSnapshotName )
110+ . write ( line: " Cloning from snapshot \" \( cloneBaseSnapshotname ) \" in base guest \" \( base. name) \" to \" \( clonedGuestName) \" ... " )
111+ clone = try base. clone ( to: clonedGuestPath, named: clonedGuestName, linkedTo: cloneBaseSnapshotname )
104112 } else {
105113 clone = VirtualMachine ( image: clonedGuestPath, executable: options. vmwareFusion)
106114 }
0 commit comments