Skip to content

Commit 2d7615b

Browse files
authored
tart clone: only reclaim unallocated bytes (#973)
1 parent 31ab421 commit 2d7615b

File tree

1 file changed

+7
-3
lines changed

1 file changed

+7
-3
lines changed

Sources/tart/Commands/Clone.swift

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ struct Clone: AsyncParsableCommand {
7171

7272
try lock.unlock()
7373

74-
// APFS is doing copy-on-write so the above cloning operation (just copying files on disk)
74+
// APFS is doing copy-on-write, so the above cloning operation (just copying files on disk)
7575
// is not actually claiming new space until the VM is started and it writes something to disk.
76-
// So once we clone the VM let's try to claim a little bit of space for the VM to run.
77-
try Prune.reclaimIfNeeded(UInt64(sourceVM.allocatedSizeBytes()), sourceVM)
76+
//
77+
// So, once we clone the VM let's try to claim the rest of space for the VM to run without errors.
78+
let unallocatedBytes = try sourceVM.sizeBytes() - sourceVM.allocatedSizeBytes()
79+
if unallocatedBytes > 0 {
80+
try Prune.reclaimIfNeeded(UInt64(), sourceVM)
81+
}
7882
}, onCancel: {
7983
try? FileManager.default.removeItem(at: tmpVMDir.baseURL)
8084
})

0 commit comments

Comments
 (0)