From ea5313698eeb8b954802afe05ce2b1f985ecd952 Mon Sep 17 00:00:00 2001 From: Fedor Korotkov Date: Mon, 15 Jul 2024 07:10:51 -0400 Subject: [PATCH] Do not prune running VMs (#861) Also prevent pushing of a running VM Fixes #860 --- Sources/tart/Commands/Push.swift | 4 ++++ Sources/tart/VMStorageLocal.swift | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Sources/tart/Commands/Push.swift b/Sources/tart/Commands/Push.swift index a8b5aa1..da31dee 100644 --- a/Sources/tart/Commands/Push.swift +++ b/Sources/tart/Commands/Push.swift @@ -33,6 +33,10 @@ struct Push: AsyncParsableCommand { func run() async throws { let ociStorage = VMStorageOCI() let localVMDir = try VMStorageHelper.open(localName) + let lock = try localVMDir.lock() + if try !lock.trylock() { + throw RuntimeError.VMIsRunning(localName) + } // Parse remote names supplied by the user let remoteNames = try remoteNames.map{ diff --git a/Sources/tart/VMStorageLocal.swift b/Sources/tart/VMStorageLocal.swift index a67bb9d..47b5b27 100644 --- a/Sources/tart/VMStorageLocal.swift +++ b/Sources/tart/VMStorageLocal.swift @@ -66,7 +66,7 @@ class VMStorageLocal: PrunableStorage { } func prunables() throws -> [Prunable] { - try list().map { (_, vmDir) in vmDir } + try list().map { (_, vmDir) in vmDir }.filter { try !$0.running() } } func hasVMsWithMACAddress(macAddress: String) throws -> Bool {