From ee6f405cabda996e1cfb46c49a140f246c2e1e11 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Sun, 25 Aug 2024 14:54:22 -0400 Subject: [PATCH 1/2] Disable local mirror on error --- lib/src/services/flutter_service.dart | 15 +++++++--- lib/src/workflows/ensure_cache.workflow.dart | 29 +++++++++++++++++-- .../resolve_dependencies.workflow.dart | 1 + 3 files changed, 38 insertions(+), 7 deletions(-) diff --git a/lib/src/services/flutter_service.dart b/lib/src/services/flutter_service.dart index af5521fb..8fec0c80 100644 --- a/lib/src/services/flutter_service.dart +++ b/lib/src/services/flutter_service.dart @@ -43,7 +43,10 @@ class FlutterService extends ContextService { } /// Clones Flutter SDK from Version Number or Channel - Future install(FlutterVersion version) async { + Future install( + FlutterVersion version, { + required bool useGitCache, + }) async { final versionDir = CacheService(context).getVersionCacheDir(version.name); // Check if its git commit @@ -75,7 +78,7 @@ class FlutterService extends ContextService { final cloneArgs = [ //if its a git hash if (!version.isCommit) ...versionCloneParams, - if (context.gitCache) ...useMirrorParams, + if (useGitCache) ...useMirrorParams, ]; try { @@ -215,13 +218,17 @@ class FlutterServiveMock extends FlutterService { FlutterServiveMock(FVMContext context) : super(context); @override - Future install(FlutterVersion version) async { + Future install( + FlutterVersion version, { + required bool useGitCache, + }) async { /// Moves directory from main context HOME/fvm/versions to test context final mainContext = FVMContext.main; var cachedVersion = CacheService(mainContext).getVersion(version); if (cachedVersion == null) { - await FlutterService(mainContext).install(version); + await FlutterService(mainContext) + .install(version, useGitCache: useGitCache); cachedVersion = CacheService(mainContext).getVersion(version); } final versionDir = CacheService(mainContext).getVersionCacheDir( diff --git a/lib/src/workflows/ensure_cache.workflow.dart b/lib/src/workflows/ensure_cache.workflow.dart index a1d3494a..41ce2286 100644 --- a/lib/src/workflows/ensure_cache.workflow.dart +++ b/lib/src/workflows/ensure_cache.workflow.dart @@ -5,6 +5,7 @@ import 'package:mason_logger/mason_logger.dart'; import '../models/cache_flutter_version_model.dart'; import '../models/flutter_version_model.dart'; import '../services/cache_service.dart'; +import '../services/config_repository.dart'; import '../services/flutter_service.dart'; import '../services/logger_service.dart'; import '../services/releases_service/releases_client.dart'; @@ -81,15 +82,37 @@ Future ensureCacheWorkflow( } } - if (ctx.gitCache) { - await FlutterService.fromContext.updateLocalMirror(); + bool useGitCache = ctx.gitCache; + + if (useGitCache) { + try { + await FlutterService.fromContext.updateLocalMirror(); + } on Exception { + useGitCache = false; + logger.warn( + 'Failed to setup local cache. Falling back to git clone.', + ); + logger.info('Git cache will be disabled.'); + try { + final config = ConfigRepository.loadAppConfig(); + final updatedConfig = config.copyWith(useGitCache: false); + ConfigRepository.save(updatedConfig); + logger.success('Git cache has been disabled.'); + } on Exception { + logger.warn('Failed to update config file'); + } + } } final progress = logger.progress( 'Installing Flutter SDK: ${cyan.wrap(validVersion.printFriendlyName)}', ); try { - await FlutterService.fromContext.install(validVersion); + await FlutterService.fromContext.install( + validVersion, + useGitCache: useGitCache, + ); + progress.complete( 'Flutter SDK: ${cyan.wrap(validVersion.printFriendlyName)} installed!', ); diff --git a/lib/src/workflows/resolve_dependencies.workflow.dart b/lib/src/workflows/resolve_dependencies.workflow.dart index 1fba8932..98763dea 100644 --- a/lib/src/workflows/resolve_dependencies.workflow.dart +++ b/lib/src/workflows/resolve_dependencies.workflow.dart @@ -65,6 +65,7 @@ Future resolveDependenciesWorkflow( final confirmation = logger.confirm( 'Would you like to continue pinning this version anyway?', + defaultValue: false, ); if (!confirmation) { From d6683a7cde9d80b2dd30565dcfac9d9c5b011e39 Mon Sep 17 00:00:00 2001 From: Leo Farias Date: Sun, 25 Aug 2024 15:45:04 -0400 Subject: [PATCH 2/2] Fixed test --- test/services/cache_service_test.dart | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/services/cache_service_test.dart b/test/services/cache_service_test.dart index 8cb946d7..15c92435 100644 --- a/test/services/cache_service_test.dart +++ b/test/services/cache_service_test.dart @@ -19,8 +19,8 @@ void main() { expect(validChannel, null); expect(validVersion, null); - await FlutterService.fromContext.install(_channel); - await FlutterService.fromContext.install(_version); + await FlutterService.fromContext.install(_channel, useGitCache: true); + await FlutterService.fromContext.install(_version, useGitCache: true); final cacheChannel = CacheService.fromContext.getVersion(_channel);