diff --git a/Sources/tart/Commands/Clone.swift b/Sources/tart/Commands/Clone.swift index 164a85ae..d09fae2d 100644 --- a/Sources/tart/Commands/Clone.swift +++ b/Sources/tart/Commands/Clone.swift @@ -77,7 +77,7 @@ struct Clone: AsyncParsableCommand { // 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) + try Prune.reclaimIfNeeded(UInt64(unallocatedBytes), sourceVM) } }, onCancel: { try? FileManager.default.removeItem(at: tmpVMDir.baseURL) diff --git a/Sources/tart/Fetcher.swift b/Sources/tart/Fetcher.swift index e56c8455..a8111046 100644 --- a/Sources/tart/Fetcher.swift +++ b/Sources/tart/Fetcher.swift @@ -55,6 +55,7 @@ fileprivate class Delegate: NSObject, URLSessionDataDelegate { buffer = Data(capacity: Int(capacity)) responseContinuation?.resume(returning: response) + responseContinuation = nil completionHandler(.allow) } @@ -76,15 +77,20 @@ fileprivate class Delegate: NSObject, URLSessionDataDelegate { task: URLSessionTask, didCompleteWithError error: Error? ) { - if !buffer.isEmpty { - streamContinuation?.yield(buffer) - buffer.removeAll(keepingCapacity: true) - } - if let error = error { + responseContinuation?.resume(throwing: error) + responseContinuation = nil + streamContinuation?.finish(throwing: error) + streamContinuation = nil } else { + if !buffer.isEmpty { + streamContinuation?.yield(buffer) + buffer.removeAll(keepingCapacity: true) + } + streamContinuation?.finish() + streamContinuation = nil } } }