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

Fixed race condition for link creation #297

Merged
merged 1 commit into from
May 19, 2021
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
7 changes: 7 additions & 0 deletions lib/src/commands/doctor_command.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'package:fvm/src/version.dart';
import 'package:io/io.dart';
import 'package:process_run/shell.dart';

Expand Down Expand Up @@ -33,6 +34,9 @@ class DoctorCommand extends BaseCommand {
final cacheVersion =
await CacheService.getByVersionName(project.pinnedVersion!);
FvmLogger.spacer();

FvmLogger.info('FVM Version: $packageVersion');
FvmLogger.divider();
FvmLogger.fine('FVM config found:');
FvmLogger.divider();
FvmLogger.info('Project: ${project.name}');
Expand Down Expand Up @@ -84,6 +88,9 @@ class DoctorCommand extends BaseCommand {
FvmLogger.info('Dart:');
FvmLogger.info(dartWhich ?? '');
FvmLogger.spacer();
FvmLogger.info('FVM_HOME:');
FvmLogger.info(kEnvVars['FVM_HOME'] ?? 'not set');
FvmLogger.spacer();

return ExitCode.success.code;
}
Expand Down
3 changes: 1 addition & 2 deletions lib/src/commands/flutter_command.dart
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ class FlutterCommand extends BaseCommand {
// Runs flutter command with pinned version
return await flutterCmd(cacheVersion, args);
} else {
// Running null will default to flutter version on path

// Running null will default to flutter version on paths
return await flutterGlobalCmd(args);
}
}
Expand Down
2 changes: 1 addition & 1 deletion lib/src/services/config_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ class ConfigService {

/// Updates link for the project SDK from the [config]
static Future<void> updateSdkLink(FvmConfig config) async {
await createLink(config.sdkSymlink, File(config.flutterSdkPath));
await createLink(config.sdkSymlink, Directory(config.flutterSdkPath));
}

/// Saves a fvm [config]
Expand Down
11 changes: 10 additions & 1 deletion lib/src/utils/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,18 @@ Future<String> getParentDirPath(String filePath) async {
/// Creates a symlink from [source] to the [target]
Future<void> createLink(Link source, FileSystemEntity target) async {
try {
if (await source.exists()) {
// Check if needs to do anything
// TODO: Move this check higher up the stack
final sourceExists = await source.exists();
if (sourceExists && await source.target() == target.path) {
logger.trace('Link is setup correctly');
return;
}

if (sourceExists) {
await source.delete();
}

await source.create(
target.path,
recursive: true,
Expand Down
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ dev_dependencies:
build_runner: ^2.0.1
build_version: ^2.0.3
effective_dart: ^1.3.1
cli_pkg:
git: https://github.com/leoafarias/dart_cli_pkg
cli_pkg: ^1.3.0

grinder: ^0.9.0
test: ^1.17.2
Expand Down
2 changes: 1 addition & 1 deletion tool/grind.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:grinder/grinder.dart';
import 'package:cli_pkg/cli_pkg.dart' as pkg;
import 'package:grinder/grinder.dart';

void main(List<String> args) {
pkg.name.value = 'fvm';
Expand Down