Skip to content

Commit

Permalink
tart clone: only reclaim unallocated bytes (#973)
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev authored Dec 12, 2024
1 parent 31ab421 commit 2d7615b
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions Sources/tart/Commands/Clone.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down

0 comments on commit 2d7615b

Please sign in to comment.