mirror of
https://github.com/cirruslabs/tart.git
synced 2026-10-18 03:53:56 +02:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
eaec015edf | ||
|
|
e27da23f4c | ||
|
|
e6a30b07e3 |
@@ -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.
|
// 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()
|
let unallocatedBytes = try sourceVM.sizeBytes() - sourceVM.allocatedSizeBytes()
|
||||||
if unallocatedBytes > 0 {
|
if unallocatedBytes > 0 {
|
||||||
try Prune.reclaimIfNeeded(UInt64(), sourceVM)
|
try Prune.reclaimIfNeeded(UInt64(unallocatedBytes), sourceVM)
|
||||||
}
|
}
|
||||||
}, onCancel: {
|
}, onCancel: {
|
||||||
try? FileManager.default.removeItem(at: tmpVMDir.baseURL)
|
try? FileManager.default.removeItem(at: tmpVMDir.baseURL)
|
||||||
|
|||||||
+17
-10
@@ -1,6 +1,6 @@
|
|||||||
import Foundation
|
import Foundation
|
||||||
|
|
||||||
fileprivate var urlSessionConfiguration: URLSessionConfiguration {
|
fileprivate var urlSession: URLSession = {
|
||||||
let config = URLSessionConfiguration.default
|
let config = URLSessionConfiguration.default
|
||||||
|
|
||||||
// Harbor expects a CSRF token to be present if the HTTP client
|
// Harbor expects a CSRF token to be present if the HTTP client
|
||||||
@@ -13,14 +13,15 @@ fileprivate var urlSessionConfiguration: URLSessionConfiguration {
|
|||||||
// [2]: https://github.com/cirruslabs/tart/issues/295
|
// [2]: https://github.com/cirruslabs/tart/issues/295
|
||||||
config.httpShouldSetCookies = false
|
config.httpShouldSetCookies = false
|
||||||
|
|
||||||
return config
|
return URLSession(configuration: config)
|
||||||
}
|
}()
|
||||||
|
|
||||||
class Fetcher {
|
class Fetcher {
|
||||||
static func fetch(_ request: URLRequest, viaFile: Bool = false, progress: Progress? = nil) async throws -> (AsyncThrowingStream<Data, Error>, HTTPURLResponse) {
|
static func fetch(_ request: URLRequest, viaFile: Bool = false, progress: Progress? = nil) async throws -> (AsyncThrowingStream<Data, Error>, HTTPURLResponse) {
|
||||||
|
let task = urlSession.dataTask(with: request)
|
||||||
|
|
||||||
let delegate = Delegate()
|
let delegate = Delegate()
|
||||||
let session = URLSession(configuration: urlSessionConfiguration, delegate: delegate, delegateQueue: nil)
|
task.delegate = delegate
|
||||||
let task = session.dataTask(with: request)
|
|
||||||
|
|
||||||
let stream = AsyncThrowingStream<Data, Error> { continuation in
|
let stream = AsyncThrowingStream<Data, Error> { continuation in
|
||||||
delegate.streamContinuation = continuation
|
delegate.streamContinuation = continuation
|
||||||
@@ -55,6 +56,7 @@ fileprivate class Delegate: NSObject, URLSessionDataDelegate {
|
|||||||
buffer = Data(capacity: Int(capacity))
|
buffer = Data(capacity: Int(capacity))
|
||||||
|
|
||||||
responseContinuation?.resume(returning: response)
|
responseContinuation?.resume(returning: response)
|
||||||
|
responseContinuation = nil
|
||||||
completionHandler(.allow)
|
completionHandler(.allow)
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -76,15 +78,20 @@ fileprivate class Delegate: NSObject, URLSessionDataDelegate {
|
|||||||
task: URLSessionTask,
|
task: URLSessionTask,
|
||||||
didCompleteWithError error: Error?
|
didCompleteWithError error: Error?
|
||||||
) {
|
) {
|
||||||
if !buffer.isEmpty {
|
|
||||||
streamContinuation?.yield(buffer)
|
|
||||||
buffer.removeAll(keepingCapacity: true)
|
|
||||||
}
|
|
||||||
|
|
||||||
if let error = error {
|
if let error = error {
|
||||||
|
responseContinuation?.resume(throwing: error)
|
||||||
|
responseContinuation = nil
|
||||||
|
|
||||||
streamContinuation?.finish(throwing: error)
|
streamContinuation?.finish(throwing: error)
|
||||||
|
streamContinuation = nil
|
||||||
} else {
|
} else {
|
||||||
|
if !buffer.isEmpty {
|
||||||
|
streamContinuation?.yield(buffer)
|
||||||
|
buffer.removeAll(keepingCapacity: true)
|
||||||
|
}
|
||||||
|
|
||||||
streamContinuation?.finish()
|
streamContinuation?.finish()
|
||||||
|
streamContinuation = nil
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user