~/bend-docscommunity

src/fetch/plan.bend fails

raw source on the hub · import ezx@1.5.0.0/src/fetch/plan.bend as Plan

fetch/plan: ez fetch as a pure planner. It reads a World (fetch/world.bend) and returns either the questions it still needs answered (step) or a Plan: the effects to run and how the command ends (plan). The interpreter (fetch/run.bend) loops on step, answering each question by IO, until nothing is left to ask, then executes the plan.

ez fetch fills BEND_LIB from the lock alone, re-resolving nothing. With no ez.toml, or no ez.lock.toml, it refuses before it asks anything, as uv sync --frozen does: a fetch never writes a lock, so it has nothing to fill BEND_LIB from.

For every package the lock records it asks first for the tree already under BEND_LIB. A tree there that the lock's checks pass is kept as it is. Any other is fetched: a git package as a shallow checkout at the pinned rev, from its source anchored at the project (P.anchor(here, url)), and a hub package from the lock's hub. Each file is then taken from what arrived by its path, from the package's root inside the checkout for a git package, and the package is checked before anything is laid (good): every file's digest equals the sum the lock records for it (EZ-FETCH-1), no path leaves the package, and the files hash to the name the lock records them under (EZ-HASH-3). A git package's checkout must also weigh to the narHash the lock records (weighed), so the files laid come from the tree the lock pins, the tree nix rebuilds from the same pin. Only then is the tree laid under BEND_LIB, the files the lock names and their manifest last.

Every name the lock records is laid too, as the file bend reads the name's hash from, $BEND_LIB/names/<nv> holding the hash and a newline, so bend never asks the hub for it (EZ-HUB-4). A names file that already holds the lock's hash is kept; any other is written, and one that held another hash is said to have been rewritten, since the lock wins over it as it wins over a tree that fails its checks. A name the lock records that bend would not read back, one the hub rules out or a hash that is not a 0x name, refuses the fetch, since its file would not be the one bend reads.

The plan of a fetch that succeeds lays every tree that was fetched and every names file that is not already right, and nothing else: no ledger, no lock. A fetch that refuses, for any package, has no effect at all, so a package fetched before the one that failed is not laid either, and a tree already under BEND_LIB is never removed (EZ-OUT-2).

The Effect, Plan and Outcome types are the lock's (lock/plan.bend), as for ez add, ez remove and ez init.

10 imports
import Base
import ../toml/toml.bend as T
import ./world.bend as F
import ../lock/plan.bend as P
import ../lock/world.bend as W
import ../lock/up.bend as Up
import ../lock/lock.bend as L
import ../pkg/pkg.bend as K
import ../pkg/path.bend as Path
import ../share/sha.bend as Sha