Repository navigation
feat: stream update downloads to disk, resume them, and verify a declared digest - #327
Conversation
…ared digest The update ZIP was fetched with a single NSURLConnection request and held in memory as one NSData before being written out, so a large update was an equally large allocation in the host app, and any interruption (network change, sleep, quit) threw the whole transfer away until the next check started it from zero. SQRLDownloader wraps an NSURLSession download task: the payload streams to a file, progress is published as it arrives, and when a transfer fails or is cancelled the session's resume data is kept beside Squirrel's update directories. The next check, in this process or after a relaunch, continues from that offset when the server answered with a validator and honours Range, and starts over otherwise. Downloads still in flight when the application terminates hand over their resume data first. SQRLUpdater uses it for the update ZIP and exposes the progress as `downloadProgress`. Feeds may now declare `sha256` and `size` for the ZIP; a download that does not match is discarded before ditto ever sees it and the check fails with SQRLUpdaterErrorInvalidUpdatePackage. Verification and installation are otherwise unchanged.
MarshallOfSound
left a comment
There was a problem hiding this comment.
Went through this pretty carefully and had most of the below repro'd against a local server rather than just reading it. The streaming side looks solid and nothing here lets a bad package actually get installed, the comments are mostly the resume state machine having a few ways to get stuck or do the wrong thing across checks/relaunches, plus the new feed fields being stricter than they look. The .. url one, resume-fails-again, the plist not being consumed and the etag ordering are the ones I think we should sort out in this PR, the rest are docs/tests.
Resume data is taken off disk while an attempt owns the partial file; a resumed request that gets nowhere (refused, reset, undecodable, or answered 403/416/304) is forgotten and retried as a plain GET once; a nil resumed task falls into the fresh path. The archive is written to a fixed name rather than one derived from the URL, the ETag is dropped when the download does not become a prepared update, and hashing reads through NSInputStream so a failing disk is an error, not an exception. `sha256`/`size` of the wrong type or shape are logged and ignored instead of failing the model. Specs cover the refused/reset resume, the no-plist-while-resuming invariant, malformed feed values, and a prepared update with a matching digest and size; README notes the protocol-class and quit-path caveats.
MarshallOfSound
left a comment
There was a problem hiding this comment.
Re-swept 898109d, everything from the first pass is sorted (re-ran the gzip / reset servers against the new nowhere check and neither gets a didWriteData before failing so both go fresh now, and the suite is green here). Two things on the new resume logic.
…anch A resumed attempt that goes nowhere is retried fresh; if that fresh attempt also receives nothing, the network rather than the ranged request is the problem, so the resume data that was taken is put back and the partial outlives the outage. The went-nowhere path can only be reached from a resumed attempt, so its second-failure branch (and the retriedFresh flag) is removed.
…ffers one (#328) Stacked on #327 (base branch `stream-and-resume-downloads`); the diff here is only the delta work. An update may now carry `delta`: a [Sparkle](https://sparkle-project.org) BinaryDelta patch (format 3 or 4) from one earlier `CFBundleVersion` to this release, with its URL, size and SHA-256: ```json "delta": { "from_version": "412", "url": "https://…/412-to-413.delta", "sha256": "…", "size": 7340032 } ``` When `from_version` is the running application's, Squirrel downloads the patch instead of the ZIP (same streaming, resumable `SQRLDownloader`), checks size and digest before opening it, applies it to a copy of the running bundle inside the update directory, and sends the result through the existing code signing and `ElectronSquirrelPreventDowngrades` checks. If the delta is for another version, or downloading, verifying, applying or checking it fails in any way, the full ZIP is downloaded in the same check, so offering a delta can never cost an update. All four keys are required; ShipIt and installation are untouched. The apply side is Sparkle's own, vendored unmodified under `Vendor/SparkleDelta` (MIT; format 3/4 reader and applier plus `bspatch`, ~2.9k lines, pinned to sparkle-project/Sparkle@cfa1190) with a small force-included config header standing in for Sparkle's xcconfig defines; the legacy XAR formats and the create side are left out, so patches are made with Sparkle's `BinaryDelta create old.app new.app out.delta` from the exact signed bundles that shipped. That keeps one implementation of the format rather than a Squirrel-flavoured second one. `objc_direct` is turned off for the vendored classes so the tests can link Sparkle's generator against them. Sizing, for a sense of why: between two consecutive releases of a large Electron app (~230 MB zipped per arch, same Electron version) the format-4 LZMA delta is 9.5 MB, applies in a few seconds, and the result is byte-identical to the shipped bundle and passes `codesign --verify --deep --strict` and Gatekeeper. Tests: `SQRLUpdaterSpec` builds real patches between the two TestApplication fixtures with Sparkle's generator (vendored into the test target only) and drives the out-of-process install twice, once from the delta alone (ZIP never requested) and once with a corrupted delta that must fall back to the ZIP, asserting on the fixture server's request log which files were fetched; `SQRLUpdateSpec` covers parsing and rejects a delta missing any key. 97 tests pass on macOS 26.5 / Xcode 26.5. README documents the key in both feed formats
…nloads Rolls squirrel.mac to fffea30 (Squirrel/Squirrel.Mac#327, #328, #330): * the update ZIP streams to disk through an NSURLSession download task instead of arriving as one in-memory NSData, an interrupted transfer resumes on the next check (and after a relaunch) when the server provides a validator and honours Range, and a feed may declare `sha256`/`size` for the ZIP, checked before it is unpacked; * a feed may offer `delta`, a Sparkle BinaryDelta patch from one earlier build, applied to a copy of the running app and verified like an unpacked ZIP, with the ZIP as fallback in the same check. Squirrel compiles Sparkle's BinaryDelta apply sources and the bsdiff it vendors into the framework, so Sparkle 2.9.5 becomes a DEPS entry at vendor/Sparkle (gclient does not initialise Squirrel's submodule) with a licenses.py entry, and the GN config gains those sources with the flags Squirrel's Xcode project gives them, the new Squirrel sources, and -lbz2 -lcompression -lz. The autoUpdater docs describe the behaviour and the optional feed keys.
…loads (#52820) * chore: roll Squirrel.Mac for streamed, resumable and delta update downloads Rolls squirrel.mac to fffea30 (Squirrel/Squirrel.Mac#327, #328, #330): * the update ZIP streams to disk through an NSURLSession download task instead of arriving as one in-memory NSData, an interrupted transfer resumes on the next check (and after a relaunch) when the server provides a validator and honours Range, and a feed may declare `sha256`/`size` for the ZIP, checked before it is unpacked; * a feed may offer `delta`, a Sparkle BinaryDelta patch from one earlier build, applied to a copy of the running app and verified like an unpacked ZIP, with the ZIP as fallback in the same check. Squirrel compiles Sparkle's BinaryDelta apply sources and the bsdiff it vendors into the framework, so Sparkle 2.9.5 becomes a DEPS entry at vendor/Sparkle (gclient does not initialise Squirrel's submodule) with a licenses.py entry, and the GN config gains those sources with the flags Squirrel's Xcode project gives them, the new Squirrel sources, and -lbz2 -lcompression -lz. The autoUpdater docs describe the behaviour and the optional feed keys. * fixup! visibility of sparkle_binary_delta mac_framework_bundle() expands squirrel_framework into inner targets (squirrel_framework_shared_library links the sources), so limit the source_set to this file rather than to the template's outer name.
…loads (#54204) feat: roll Squirrel.Mac for streamed, resumable and delta update downloads (#52820) * chore: roll Squirrel.Mac for streamed, resumable and delta update downloads Rolls squirrel.mac to fffea30 (Squirrel/Squirrel.Mac#327, #328, #330): * the update ZIP streams to disk through an NSURLSession download task instead of arriving as one in-memory NSData, an interrupted transfer resumes on the next check (and after a relaunch) when the server provides a validator and honours Range, and a feed may declare `sha256`/`size` for the ZIP, checked before it is unpacked; * a feed may offer `delta`, a Sparkle BinaryDelta patch from one earlier build, applied to a copy of the running app and verified like an unpacked ZIP, with the ZIP as fallback in the same check. Squirrel compiles Sparkle's BinaryDelta apply sources and the bsdiff it vendors into the framework, so Sparkle 2.9.5 becomes a DEPS entry at vendor/Sparkle (gclient does not initialise Squirrel's submodule) with a licenses.py entry, and the GN config gains those sources with the flags Squirrel's Xcode project gives them, the new Squirrel sources, and -lbz2 -lcompression -lz. The autoUpdater docs describe the behaviour and the optional feed keys. * fixup! visibility of sparkle_binary_delta mac_framework_bundle() expands squirrel_framework into inner targets (squirrel_framework_shared_library links the sources), so limit the source_set to this file rather than to the template's outer name. (cherry picked from commit fd93bf4)
The update ZIP is fetched with a single
NSURLConnection sendAsynchronousRequest:and held as oneNSDatabefore it is written out, so a large update is an equally large allocation in the host app, and any interruption (network change, sleep, quit) discards the whole transfer until the next check starts it again from zero.NSURLConnectionhas also been deprecated since 10.11.This adds
SQRLDownloader, a small wrapper around anNSURLSessiondownload task, and moves-downloadBundleForUpdate:intoDirectory:onto it:update.XXXXXXXdirectories (download.resumedata), and the next check continues from that offset with aRangerequest instead of starting over; this holds after a relaunch too, since downloads still in flight atNSApplicationWillTerminateNotificationhand over their resume data firstSQRLDownloadProgressvalues on the newSQRLUpdater.downloadProgressSQRLDownloader.sessionConfigurationlets a host set network policy or protocol classes for the download sessionsSeparately, an update may now declare
sha256andsizefor its ZIP (SQRLUpdate.packageDigest/packageSize, both optional). A download that does not match is deleted beforedittoruns and the check errors withSQRLUpdaterErrorInvalidUpdatePackage. Signature verification and installation are untouched.Tests:
SQRLDownloaderSpecruns against a small local HTTP server (SquirrelTests/TestServer.py, ranges + ETag, can cut a transfer short) and covers a full download with progress, resuming an interrupted transfer (asserts theRangerequest and a byte-identical result), keeping resume data on disposal and on+cancelAllWritingResumeDataWithTimeout:, and discarding resume data for another URL.SQRLUpdaterSpecgains the digest/size rejection case andSQRLUpdateSpecthe parsing; the existing out-of-process update specs exercise the new path end to end overfile://. 94 tests pass locally on macOS 26.5 / Xcode 26.5