Skip to content

Commit

Permalink
Merge pull request #318 from leoafarias/feature/remove_symlink_check
Browse files Browse the repository at this point in the history
Feature/remove symlink check
  • Loading branch information
leoafarias authored Jun 14, 2021
2 parents f1e36f4 + 3559b2a commit 42f358a
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 54 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 2.1.0

- Removed Windows permission check

## 2.0.7

- Updated Flutter releases URL
Expand Down
8 changes: 2 additions & 6 deletions lib/src/runner.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ import 'commands/releases_command.dart';
import 'commands/remove_command.dart';
import 'commands/spawn_command.dart';
import 'commands/use_command.dart';
import 'utils/guards.dart';
import 'utils/helpers.dart';
import 'utils/logger.dart';
import 'version.dart';
Expand Down Expand Up @@ -67,14 +66,11 @@ class FvmCommandRunner extends CommandRunner<int> {
ConsoleController.isCli = true;
final _argResults = parse(args);

// Check that can symlink
await Guards.canSymlink();

final exitCode = await runCommand(_argResults) ?? ExitCode.success.code;

// Command might be null
final cmd = _argResults.command?.name;

final exitCode = await runCommand(_argResults) ?? ExitCode.success.code;

// Check if its running the latest version of FVM
if (cmd == 'use' || cmd == 'install' || cmd == 'remove') {
// Check if there is an update fofr FVM
Expand Down
8 changes: 0 additions & 8 deletions lib/src/services/context.dart
Original file line number Diff line number Diff line change
Expand Up @@ -75,14 +75,6 @@ class FvmContext {
/// Where Default Flutter SDK is stored
Link get globalCacheLink => Link(join(_fvmDir.path, 'default'));

/// Used to test that it can link
Link get testLinkSource => Link(join(_fvmDir.path, '.test_link'));

/// Used to test it links to target
Directory get testLinkTarget => Directory(
join(_fvmDir.path, '.test_link_target'),
);

/// Directory for Global Flutter SDK bin
String get globalCacheBinPath => join(
globalCacheLink.path,
Expand Down
36 changes: 0 additions & 36 deletions lib/src/utils/guards.dart
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
import 'dart:io';

import 'package:io/io.dart';

import '../../exceptions.dart';
import '../services/context.dart';
import 'helpers.dart';
import 'logger.dart';

/// Guards against certain action by validatin and throwing errors
class Guards {
Expand All @@ -15,35 +10,4 @@ class Guards {
throw FvmInternalError('Cannot execute $execPath');
}
}

/// Checks if user can create symlink
static Future<void> canSymlink() async {
if (!Platform.isWindows) return;
try {
if (!await ctx.testLinkTarget.exists()) {
await ctx.testLinkTarget.create(recursive: true);
}
await createLink(ctx.testLinkSource, ctx.testLinkTarget);
} on Exception catch (err) {
logger.trace(err.toString());
var message = '';
if (Platform.isWindows) {
message = 'On Windows FVM requires to run as an administrator '
'or turn on developer mode: https://bit.ly/3vxRr2M';
}

throw FvmUsageException(
"Seems you don't have the required permissions on ${ctx.fvmHome.path}"
' $message',
);
} finally {
// Clean up
if (await ctx.testLinkSource.exists()) {
await ctx.testLinkSource.delete();
}
if (await ctx.testLinkTarget.exists()) {
await ctx.testLinkTarget.delete();
}
}
}
}
15 changes: 13 additions & 2 deletions lib/src/utils/helpers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:path/path.dart';
import 'package:process_run/shell.dart';

import '../../constants.dart';
import '../../exceptions.dart';
import '../services/context.dart';
import '../version.dart';
import 'logger.dart';
Expand Down Expand Up @@ -71,8 +72,18 @@ Future<void> createLink(Link source, FileSystemEntity target) async {
recursive: true,
);
} on FileSystemException catch (e) {
logger.trace(e.message);
rethrow;
logger.trace(e.toString());

var message = '';
if (Platform.isWindows) {
message = 'On Windows FVM requires to run as an administrator '
'or turn on developer mode: https://bit.ly/3vxRr2M';
}

throw FvmUsageException(
"Seems you don't have the required permissions on ${ctx.fvmHome.path}"
' $message',
);
}
}

Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name: fvm
description: A simple cli to manage Flutter SDK versions per project. Support
channels, releases, and local cache for fast switching between versions.
version: 2.0.7
version: 2.1.0
homepage: https://github.com/leoafarias/fvm

environment:
Expand Down

0 comments on commit 42f358a

Please sign in to comment.