From 14cbc727adafb0449f54da71ddb580bbc592bf38 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Mon, 21 Nov 2022 17:42:53 +0400 Subject: [PATCH] tart run: check if the disks are locked (#333) --- Sources/tart/Commands/Run.swift | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/Sources/tart/Commands/Run.swift b/Sources/tart/Commands/Run.swift index f57c66f..8df0b43 100644 --- a/Sources/tart/Commands/Run.swift +++ b/Sources/tart/Commands/Run.swift @@ -90,10 +90,23 @@ struct Run: AsyncParsableCommand { @MainActor func run() async throws { let vmDir = try VMStorageLocal().open(name) + + let additionalDiskAttachments = try additionalDiskAttachments() + + // Error out if the disk is locked by the host (e.g. it was mounted in Finder), + // see https://github.com/cirruslabs/tart/issues/323 for more details. + for additionalDiskAttachment in additionalDiskAttachments { + if try !FileLock(lockURL: additionalDiskAttachment.url).trylock() { + print("disk \(additionalDiskAttachment.url.path) seems to be already in use, " + + "unmount it first in Finder") + Foundation.exit(1) + } + } + vm = try VM( vmDir: vmDir, network: userSpecifiedNetwork(vmDir: vmDir) ?? NetworkShared(), - additionalDiskAttachments: additionalDiskAttachments(), + additionalDiskAttachments: additionalDiskAttachments, directoryShares: directoryShares() )