InstallTransaction class
Orchestrator that stages a list of InstallOperations and either applies them atomically to disk, renders a dry-run preview, or refuses to write when ConflictDetector flags a target file the user has modified out-of-band.
Commit semantics are all-or-nothing:
- Every file write lands on
<absPath>.tmpfirst via InstallContext.fs. - Only after every
.tmpwrite succeeds do the renames + deletes apply. - If any
.tmpwrite throws, every staged.tmpis removed and the method returns an Error withrolledBack: true.
One-shot: each InstallTransaction instance commits exactly once. A second commit throws StateError so callers cannot replay operations against stale state.
Usage
final tx = InstallTransaction(ctx, pluginName: 'firebase_messaging');
tx.stage(const WriteFile(targetPath: 'lib/config/firebase.dart', content: '...'));
tx.stage(const InjectImport(targetFile: 'lib/main.dart', importStatement: "..."));
final result = await tx.commit();
switch (result) {
case Success(:final opCount, :final recordPath):
ctx.artisanContext.output.success('Installed $opCount ops; record: $recordPath');
case DryRun(:final opCount):
ctx.artisanContext.output.info('Previewed $opCount ops; nothing written');
case Conflict(:final conflicts):
ctx.artisanContext.output.warning('${conflicts.length} conflicts; pass --force to override');
case Error(:final error, :final rolledBack):
ctx.artisanContext.output.error('Failed: $error (rolled back: $rolledBack)');
}
Constructors
- InstallTransaction(InstallContext ctx, {required String pluginName})
-
Creates a transaction bound to
ctxfor the plugin identified bypluginName. The plugin name threads into the.artisan/installed/<pluginName>.jsonrecord path written on success.
Properties
- hashCode → int
-
The hash code for this object.
no setterinherited
- pendingCount → int
-
Number of operations staged but not yet committed.
no setter
-
pendingOps
→ List<
InstallOperation> -
Read-only view of the staged operations in insertion order. Mutating
the returned list throws UnsupportedError.
no setter
- runtimeType → Type
-
A representation of the runtime type of the object.
no setterinherited
Methods
-
commit(
{bool dryRun = false, bool force = false}) → Future< TransactionResult> - Executes the staged operations.
-
debugSetConflictsForTest(
List< FileConflict> conflicts) → void -
Test-only seam (will be removed once Step 7's
ConflictDetectoris wired): pre-populates the conflict list returned by_detectConflicts. -
noSuchMethod(
Invocation invocation) → dynamic -
Invoked when a nonexistent method or property is accessed.
inherited
-
stage(
InstallOperation op) → void -
Appends
opto the staged operation queue. -
toString(
) → String -
A string representation of this object.
inherited
Operators
-
operator ==(
Object other) → bool -
The equality operator.
inherited