relock method
- String project, {
- required FutureOr<
String> edit(- String configuration
- WayfinderCancellation? cancel,
Applies edit to the project's wayfinder.json and writes
wayfinder.lock for the edited configuration, keeping exactly the
commits the lock pins, under one hold of the project's get lock.
The lock's hash covers the whole configuration, actors and project
vocabulary included, so registering an actor makes the lock stale
although its Profiles stay the same. Relocking makes that edit and
writes the lock get would write for it, offline: edit receives the
configuration's text, read while the lock is held, and returns the new
text, such as one WayfinderConfigEditor made with
encode(minimal: true). Relocking then, before writing anything:
- refuses new text that is not a valid configuration
(
config-invalid); - throws ProfileLockChangeRequiredException (
lock-change-required), whosechangesays why, unless the lock pins, for the edited configuration, exactly each binding's chain at the source it names and nothing more. A missing lock or one that does not parse, a new or removed binding or Profile, another source, ref or path, and a lock entry no binding reaches need a resolution, which may fetch; - checks the configured bundles as
getdoes, and selects each binding's chain from the Profile cache as select does, composed with the edited project vocabulary. It throws what selection would report as a WayfinderProfileResolutionException, such as a package missing from the cache (profile-unresolved, whoseremedysays what fills it) or a chain that no longer composes (profile-composition).
It then writes the edited text, when its bytes change, and the lock with the edited configuration's hash and the same packages, when its hash changes: a lock whose hash already matches keeps its bytes, while one an earlier edit left stale is written as well. Each file is replaced through a temporary file beside it, so a failed write leaves that file as it was.
When the file system refuses to read or replace either file, it
throws ProfileRelockFailedException (relock-failed), naming the
path and the operating system's reason. Once a write fails, each file
relocking already wrote gets its original bytes back where the file
system allows; the exception's changed lists each one that could not,
and is empty when both files hold the bytes they held before.
It runs no Git command, so it never fetches or resolves a ref, and
leaves Profile skills alone, as a plan with skills: false does: it
writes and deletes no skill directory. It holds the project's get
lock throughout, so it throws ProfileResolutionBusyException
(resolution-busy) while a get, an apply, an adoption or another
relock holds it, and they are refused while it runs; a plan made before
it no longer applies (resolution-stale). It throws
resolution-stale itself when wayfinder.json or wayfinder.lock
changed after it read them, by a writer that holds no lock, such as an
editor. cancel is checked between steps, until writing starts.
Implementation
Future<ProfileRelockResult> relock(
String project, {
required FutureOr<String> Function(String configuration) edit,
WayfinderCancellation? cancel,
}) async {
throwIfCancelled(cancel);
final (:projectRoot, :configFile) = await _locate(project);
return _withProjectLock(
projectRoot,
() => _relock(projectRoot, configFile, edit, cancel),
);
}