From 2d7615bdf8835320fcc2b9ac74b7b5ccaa64aeb4 Mon Sep 17 00:00:00 2001 From: Nikolay Edigaryev Date: Fri, 13 Dec 2024 02:41:26 +0400 Subject: [PATCH] tart clone: only reclaim unallocated bytes (#973) --- Sources/tart/Commands/Clone.swift | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/Sources/tart/Commands/Clone.swift b/Sources/tart/Commands/Clone.swift index 4499700..164a85a 100644 --- a/Sources/tart/Commands/Clone.swift +++ b/Sources/tart/Commands/Clone.swift @@ -71,10 +71,14 @@ struct Clone: AsyncParsableCommand { try lock.unlock() - // APFS is doing copy-on-write so the above cloning operation (just copying files on disk) + // APFS is doing copy-on-write, so the above cloning operation (just copying files on disk) // is not actually claiming new space until the VM is started and it writes something to disk. - // So once we clone the VM let's try to claim a little bit of space for the VM to run. - try Prune.reclaimIfNeeded(UInt64(sourceVM.allocatedSizeBytes()), sourceVM) + // + // So, once we clone the VM let's try to claim the rest of space for the VM to run without errors. + let unallocatedBytes = try sourceVM.sizeBytes() - sourceVM.allocatedSizeBytes() + if unallocatedBytes > 0 { + try Prune.reclaimIfNeeded(UInt64(), sourceVM) + } }, onCancel: { try? FileManager.default.removeItem(at: tmpVMDir.baseURL) })