Every launch of a source install wrote inside the dependency tree: a lease
file in the selected generation (`<generation>/.leases/<uuid>`, for both
`environments/` and `pm-runtime/generations/`), `installs/<key>/.install.lock`
and `pm-runtime/.prepare.lock`. Generation names change with every build, so
a sandbox policy (Landlock/OpenShell, rootless Podman, systemd
`ReadOnlyPaths=`) could not keep the dependencies read-only without a new
exception per build: on a read-only generation `lease_directory` raised
PermissionError.
Leases now live in `installs/<key>/leases/{environments,pm-runtime}/<generation>/`
and the locks in `installs/<key>/locks/{install,prepare}.lock`. Neither path
changes between builds, so a sandbox grants write access to those two
directories and keeps the generations read-only.
- `lease_dirs(generation)` finds the install state from the generation's
parents (`environments/<gen>`, `pm-runtime/generations/<gen>`; a PM
worker's `sys.prefix` is the latter). It returns the new directory first
and the in-generation `.leases` second.
- Processes started on an earlier release keep leasing `<gen>/.leases` and
locking the old files until they exit. The collectors
(`collect_generations`, `collect_runtime_generations`, orphan reclaim)
treat a lease in either place as held, and drop the lease directories of
generations they removed.
- `moved_lock(old, new)` takes the old lock first, then the new one, so an
old process and a new one always contend on one file in one order. An old
lock this process may only read (EACCES/EPERM/EROFS) is flocked through a
read-only descriptor; it is skipped only when it cannot be opened at all.
- `_last_used` also reads the `leases/*/*` mtimes, so a launch still counts
as recent use for orphan reclaim.
- Orphan reclaim unlinks `locks/` with the old `.install.lock`, last: on
Windows an open lock file cannot be unlinked.
`runtime_lock`, `collect_generations` and the other frozen old-updater names
keep their signatures.
Refs #151951