Notes · · 1 min read
Replacing an offline pack without breaking it
An update that fails halfway must leave the old map working. The order of three small steps makes that certain.
An offline pack is often the only map a crew has, so updating it must never leave them with nothing. Downloads in the field fail all the time: the signal drops, the battery runs out, the app is closed. The update has to be safe at every moment.
Three steps, in this order. Download the new pack to a temporary file next to the old one, resuming with HTTP range requests if the connection breaks. Check it against the manifest, its size first and then its SHA-256 checksum, as described on our formats page. Only then rename it over the old pack. On the same storage a rename replaces the file in a single step, so the app sees either the whole old pack or the whole new one, never a mixture.
The old pack is removed last, once the new one has opened and drawn a map. Until then the app can still fall back.
The same rule is why we never update a pack in place on a device, even when the format allows it, as an MBTiles database does: a crew holds a complete map from one date, and the app always knows which.