Skip to content

Commit

Permalink
tart set: make --disk-size change idempotent (#698)
Browse files Browse the repository at this point in the history
...when the size is not changed.
  • Loading branch information
edigaryev authored Jan 8, 2024
1 parent fbc4812 commit 96f6f94
Showing 1 changed file with 3 additions and 2 deletions.
5 changes: 3 additions & 2 deletions Sources/tart/VMDirectory.swift
Original file line number Diff line number Diff line change
Expand Up @@ -138,13 +138,14 @@ struct VMDirectory: Prunable {
let diskFileHandle = try FileHandle.init(forWritingTo: diskURL)
let currentDiskFileLength = try diskFileHandle.seekToEnd()
let desiredDiskFileLength = UInt64(sizeGB) * 1000 * 1000 * 1000
if desiredDiskFileLength <= currentDiskFileLength {
if desiredDiskFileLength < currentDiskFileLength {
let currentLengthHuman = ByteCountFormatter().string(fromByteCount: Int64(currentDiskFileLength))
let desiredLengthHuman = ByteCountFormatter().string(fromByteCount: Int64(desiredDiskFileLength))
throw RuntimeError.InvalidDiskSize("new disk size of \(desiredLengthHuman) should be larger " +
"than the current disk size of \(currentLengthHuman)")
} else if desiredDiskFileLength > currentDiskFileLength {
try diskFileHandle.truncate(atOffset: desiredDiskFileLength)
}
try diskFileHandle.truncate(atOffset: desiredDiskFileLength)
try diskFileHandle.close()
}

Expand Down

0 comments on commit 96f6f94

Please sign in to comment.