materializePhase1 function
MaterializeResult
materializePhase1({
- required ChangePlan plan,
- required String stagingRoot,
- required String canonicalDestination,
- ApplyFileSystem fileSystem = const ApplyFileSystem(),
Implementation
MaterializeResult materializePhase1({
required ChangePlan plan,
required String stagingRoot,
required String canonicalDestination,
ApplyFileSystem fileSystem = const ApplyFileSystem(),
}) {
final operations =
plan.operations
.where((operation) => operation.ownershipClass.isMaterialized)
.toList()
..sort((a, b) => a.logicalPath.compareTo(b.logicalPath));
final applied = <AppliedFile>[];
for (final operation in operations) {
final source = applyPath(stagingRoot, operation.logicalPath);
final target = applyPath(canonicalDestination, operation.logicalPath);
final bytes = fileSystem.readBytes(source);
_verify(bytes, operation.contentHash, operation.logicalPath, 'staged');
fileSystem.createDirectory(File(target).parent.path);
if (fileSystem.fileExists(target)) {
_replaceAtomically(fileSystem, target, bytes, operation);
} else {
fileSystem.writeNew(target, bytes);
}
final finalBytes = fileSystem.readBytes(target);
_verify(finalBytes, operation.contentHash, operation.logicalPath, 'target');
applied.add(AppliedFile(operation.logicalPath, computeRawHash(finalBytes)));
}
return MaterializeResult(List.unmodifiable(applied));
}