Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable local mirror on error #766

Merged
merged 5 commits into from
Aug 25, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -82,15 +83,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
4 changes: 2 additions & 2 deletions test/services/cache_service_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
Loading