Skip to content

Commit

Permalink
Disable local mirror on error
Browse files Browse the repository at this point in the history
  • Loading branch information
leoafarias committed Aug 25, 2024
1 parent 145a9b8 commit ee6f405
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 7 deletions.
15 changes: 11 additions & 4 deletions lib/src/services/flutter_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,10 @@ class FlutterService extends ContextService {
}

/// Clones Flutter SDK from Version Number or Channel
Future<void> install(FlutterVersion version) async {
Future<void> install(
FlutterVersion version, {
required bool useGitCache,
}) async {
final versionDir = CacheService(context).getVersionCacheDir(version.name);

// Check if its git commit
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -215,13 +218,17 @@ class FlutterServiveMock extends FlutterService {
FlutterServiveMock(FVMContext context) : super(context);

@override
Future<void> install(FlutterVersion version) async {
Future<void> 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(
Expand Down
29 changes: 26 additions & 3 deletions lib/src/workflows/ensure_cache.workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down Expand Up @@ -81,15 +82,37 @@ Future<CacheFlutterVersion> 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!',
);
Expand Down
1 change: 1 addition & 0 deletions lib/src/workflows/resolve_dependencies.workflow.dart
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ Future<void> resolveDependenciesWorkflow(

final confirmation = logger.confirm(
'Would you like to continue pinning this version anyway?',
defaultValue: false,
);

if (!confirmation) {
Expand Down

0 comments on commit ee6f405

Please sign in to comment.