macOS updater: reuse unchanged files from the installed app (delta updates)

Aperta
#930 0 commenti 0 reazioni 0 assegnatari Vedi su GitHub

I maintainer di solito rispondono entro 1 giorno

Nessuno ha ancora preso questa issue.

Valutazione

Difficoltà
4/5
Tempo stimato
3-5 giorni
Idoneità per principianti
35/100
Tipo di issue
Funzionalità
Chiarezza
Specificata chiaramente
Stato di attività
Attiva
Stack tecnologico
macos, zig

Direzione di ricerca

Start with installDownloadedUpdate in src/platform/macos/appkit_host.m and the native update sign command to understand the current feed, archive-verification, staging, and install flow. The proposed path must add a separately signed delta feed, file manifests, base-version patch generation, staging, and whole-tree verification while retaining the full-ZIP fallback. Done means an applicable patch reuses byte-identical installed files, and any missing base, mismatch, or verification failure safely falls back to the full update.

Scritto dal modello di indicizzazione a partire dal testo della issue.

Descrizione

The problem

The macOS updater downloads the whole app on every update. In installDownloadedUpdate (src/platform/macos/appkit_host.m), it checks the ZIP’s size and SHA-256 against the signed feed, extracts it with ditto, and swaps the bundle with mv. It never reuses a file from the installed copy, even when most of the bundle hasn’t changed. This is true in 0.11.0 and on current main.

That gets expensive for an app that ships large files that rarely change. Sage, a Native SDK 0.11.0 app, carries a pinned Ollama (local AI server) and a pinned Node.js in Contents/Resources. Its update ZIPs:

Release Update ZIP Notes
0.2.2 78 MB before Ollama was bundled
0.3.0 226 MB first with Ollama
0.6.0 225 MB same Ollama as 0.3.0

About 148 MB of each update is the same Ollama files. Six updates have shipped since 0.3.0, so a user who installed them all downloaded the same Ollama bytes six times, about 0.9 GB.

The app can’t work around this on its own side. Moving the large files out of the bundle means the app has to download, check, and clean them up itself. It also takes them out from under the app’s code signature. The updater already knows both bundles, so it is the right place to skip the unchanged files.

The proposal

Add an optional delta path that reuses unchanged files from the installed bundle, and keep the full ZIP as the fallback.

What a release publishes
  1. The full update ZIP and native-update.json, exactly as today.
  2. A file list for the new bundle. It gives every file’s relative path, size, mode, and SHA-256, plus each symlink and its target.
  3. One patch ZIP for each recent base version. It holds only the files that are new or changed since that version.
  4. A second signed feed, such as native-update-delta.json. It holds the file list’s URL, size, and SHA-256, and, for each patch, the base version, URL, size, and SHA-256.

The file list doesn’t fit in the existing payload. Sage’s bundle has 8,118 files, and max_payload_bytes is 32 KB. So the signed feed carries the list’s hash, and the list itself is a separate download.

The delta feed has to be a separate file. verifyEnvelope parses both the envelope and the payload with ignore_unknown_fields = false. A new field in native-update.json would make every installed 0.11.0 copy reject the feed, so those copies could never update again. A separate file leaves them on the full ZIP.

What the updater does
  1. Fetch and verify native-update-delta.json with the same key as the main feed. If it’s missing or has no patch for the installed version, use the full ZIP.
  2. Download the file list and the matching patch, and check each against its signed size and SHA-256.
  3. Clone the installed bundle into the staging folder it already uses, .<App>.app.native-update-<uuid> next to the app. APFS clonefile makes this instant and uses no extra disk space. On another file system, copy it instead.
  4. Extract the patch over the clone, then delete every file the list doesn’t name.
  5. Check the whole staged tree against the file list: paths, sizes, modes, symlink targets, and SHA-256. Any difference, such as a file someone changed in the installed copy, sends it back to the full ZIP.
  6. Run the checks it runs today: bundle ID, version, and the codesign requirement when the app has a team ID.
  7. Swap the bundle with the same install script, so rollback stays as it is.
What native update sign gains
  • A way to pass the update ZIPs of earlier releases, such as --base <zip> given more than once. It writes the file list, one patch ZIP for each base, and the signed delta feed.
  • The same archive checks it runs today, on the new bundle.

Notes

  • Unchanged files must be byte-identical. For Sage they are. The bundled Ollama files match the cached download byte for byte, because codesign --deep leaves Contents/Resources alone. Ad-hoc signing an unchanged Mach-O twice also gives identical bytes.
  • Skipped versions. A user who skips several releases may have no matching patch. Publishing patches against the last few versions covers most people, and the full ZIP covers the rest.
  • Why not one asset per file. A GitHub release holds at most 1,000 assets, and an app like Sage has thousands of files. One patch ZIP per base version keeps the asset count small.
  • What it saves. The most a delta can be is everything that isn’t Ollama, which was 78 MB at 0.2.2. It is smaller when Node and the agent’s dependencies don’t change either.
Lingua principale
Zig
Stelle
7.9k
Fork
335
Merge medio
10h 33m
PR unite (30g)
147

Preparare l'ambiente

Come iniziare

  1. Leggi tutta la issue e poi la guida ai contributi del progetto.
  2. Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
  3. Fai un fork del repository e lavora su un branch.
  4. Apri una pull request che faccia riferimento al numero della issue.

Altre issue di vercel-labs/native

Tutte le issue di vercel-labs/native

Issue simili

Altre issue su Desktop Dev

Ricevi le nuove issue nella tua casella

Un breve riepilogo di issue GitHub adatte ai principianti.