resolve method
Resolves the toolchain pinned by lock, verifying every recorded file. Throws
ToolchainUnavailableException when it is missing or modified; there is no fallback.
Developer/owner escape hatch: FLUTTER_OTA_TOOLCHAIN_DIR=<dir> uses an already-installed
toolchain directory instead of the cache entry. Its install.json must still name the
pinned toolchain, and every recorded file is verified exactly as for a cache install.
Implementation
Future<ResolvedToolchain> resolve(Lockfile lock, {String? lockPath}) async {
final override = toolchainDirOverride;
final dir = override ?? cache.toolchainDir(lock.toolchain);
final rec = readInstallRecord(dir);
if (rec == null) {
throw ToolchainUnavailableException(
override != null
? '$toolchainDirEnv=$override is not an installed toolchain (no valid $installRecordName).\n'
'flutter_ota never falls back to a stock or global Flutter SDK.'
: 'The toolchain ${lock.toolchain} pinned in $lockFileName is not installed.\n'
'Install it with: flutter_ota toolchain install\n'
'flutter_ota never falls back to a stock or global Flutter SDK.',
);
}
if (override != null && rec['toolchain'] != lock.toolchain) {
throw ToolchainUnavailableException(
'$toolchainDirEnv=$override contains ${rec['toolchain']}, but $lockFileName pins ${lock.toolchain}.',
);
}
if (rec['toolchain_id'] != lock.toolchainId || rec['engine'] != lock.engine || rec['flutter'] != lock.flutter) {
throw ToolchainUnavailableException(
'The installed toolchain ${lock.toolchain} does not match $lockFileName '
'(different toolchain_id). Reinstall it with: flutter_ota toolchain install --force',
);
}
final bad = await verifyRecordedFiles(dir, rec);
if (bad.isNotEmpty) {
throw ToolchainUnavailableException(
'The installed toolchain ${lock.toolchain} failed verification '
'(${bad.take(3).join(', ')}${bad.length > 3 ? ', ...' : ''}).\n'
'Reinstall it with: flutter_ota toolchain install --force\n'
'flutter_ota never falls back to a stock or global Flutter SDK.',
);
}
if (lockPath != null && override == null) recordProjectUse(lockPath, lock.toolchain);
return ResolvedToolchain(lock.toolchain, lock.toolchainId, dir);
}