Skip to content

Commit

Permalink
tart create --from-ipsw: do a HEAD instead of a GET first (#599)
Browse files Browse the repository at this point in the history
  • Loading branch information
edigaryev authored Sep 14, 2023
1 parent d4d3852 commit 27cadc3
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions Sources/tart/VM.swift
Original file line number Diff line number Diff line change
Expand Up @@ -71,9 +71,11 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {

static func retrieveIPSW(remoteURL: URL) async throws -> URL {
// Check if we already have this IPSW in cache
let (channel, response) = try await Fetcher.fetch(URLRequest(url: remoteURL), viaFile: true)
var headRequest = URLRequest(url: remoteURL)
headRequest.httpMethod = "HEAD"
let (_, headResponse) = try await Fetcher.fetch(headRequest, viaFile: false)

if let hash = response.value(forHTTPHeaderField: "x-amz-meta-digest-sha256") {
if let hash = headResponse.value(forHTTPHeaderField: "x-amz-meta-digest-sha256") {
let ipswLocation = try IPSWCache().locationFor(fileName: "sha256:\(hash).ipsw")

if FileManager.default.fileExists(atPath: ipswLocation.path) {
Expand All @@ -87,6 +89,8 @@ class VM: NSObject, VZVirtualMachineDelegate, ObservableObject {
// Download the IPSW
defaultLogger.appendNewLine("Fetching \(remoteURL.lastPathComponent)...")

let (channel, response) = try await Fetcher.fetch(URLRequest(url: remoteURL), viaFile: true)

let progress = Progress(totalUnitCount: response.expectedContentLength)
ProgressObserver(progress).log(defaultLogger)

Expand Down

0 comments on commit 27cadc3

Please sign in to comment.