Skip to content

Commit

Permalink
Merge branch 'main' into enhancement/increase-logging
Browse files Browse the repository at this point in the history
# Conflicts:
#	Packages/TartVirtualMachine/Sources/EphemeralTartVirtualMachine/EphemeralTartVirtualMachine.swift
  • Loading branch information
simonbs committed Jun 15, 2023
2 parents c636df3 + cba8ddb commit 4e501ca
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,9 @@ public final class EphemeralTartVirtualMachine: VirtualMachine {
}

public func stop() async throws {
defer {
onCleanup()
}
try await tart.delete(name: destinationVMName)
onCleanup()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,9 @@ public struct VirtualMachineResourcesCopier {
for sourceFileURL in sourceFileURLs {
let destinationFileURL = destinationDirectoryURL.appending(path: sourceFileURL.lastPathComponent)
do {
try fileSystem.removeItem(at: destinationFileURL)
if fileSystem.itemExists(at: destinationFileURL) {
try fileSystem.removeItem(at: destinationFileURL)
}
} catch {
// Log the error but don't rethrow it as it is not severe.
// swiftlint:disable:next line_length
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public struct VirtualMachineResourcesServiceEditor: VirtualMachineResourcesServi
}

public func removeResources() throws {
try fileSystem.removeItem(at: directoryURL)
if fileSystem.itemExists(at: directoryURL) {
try fileSystem.removeItem(at: directoryURL)
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,9 @@ public struct VirtualMachineResourcesServiceEphemeral: VirtualMachineResourcesSe
}

public func removeResources() throws {
try fileSystem.removeItem(at: directoryURL)
if fileSystem.itemExists(at: directoryURL) {
try fileSystem.removeItem(at: directoryURL)
}
}
}

Expand Down
28 changes: 14 additions & 14 deletions Tartelet/Sources/Composition/EphemeralVirtualMachineFactory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -39,25 +39,25 @@ struct EphemeralVirtualMachineFactory: VirtualMachineFactory {
logger.error("Failed making ephemeral virtual machine as name is not available")
throw EphemeralVirtualMachineFactoryError.sourceVirtualMachineNameUnavailable
}
let resourcesService = resourcesServiceFactory.makeService(virtualMachineName: name)
do {
let resourcesService = resourcesServiceFactory.makeService(virtualMachineName: name)
try await resourcesService.createResourcesIfNeeded()
// swiftlint:disable:next trailing_closure
return EphemeralTartVirtualMachine(
tart: tart,
sourceVMName: sourceVMName,
destinationVMName: name,
resourcesDirectoryURL: resourcesService.directoryURL,
onCleanup: {
do {
try resourcesService.removeResources()
} catch {
logger.error("Failed cleaning up resources for ephemeral virtual machine: \(error.localizedDescription, privacy: .public)")
}
})
} catch {
logger.error("Failed making ephemeral virtual machine as resources could not be created: \(error.localizedDescription, privacy: .public)")
throw error
}
// swiftlint:disable:next trailing_closure
return EphemeralTartVirtualMachine(
tart: tart,
sourceVMName: sourceVMName,
destinationVMName: name,
resourcesDirectoryURL: resourcesService.directoryURL,
onCleanup: {
do {
try resourcesService.removeResources()
} catch {
logger.error("Failed cleaning up resources for ephemeral virtual machine: \(error.localizedDescription, privacy: .public)")
}
})
}
}

0 comments on commit 4e501ca

Please sign in to comment.