Skip to content

Commit d4d10da

Browse files
Revert "Check whether FLUTTER_ROOT and FLUTTER_ROOT/bin are writable. (flutter#34291)" (flutter#34750)
This reverts commit 4944950.
1 parent c8c20fb commit d4d10da

File tree

4 files changed

+10
-94
lines changed

4 files changed

+10
-94
lines changed

packages/flutter_tools/lib/src/cache.dart

Lines changed: 1 addition & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -95,49 +95,8 @@ class Cache {
9595
final Directory _rootOverride;
9696
final List<CachedArtifact> _artifacts = <CachedArtifact>[];
9797

98-
// Check whether there is a writable bit in the usr permissions.
99-
static bool _hasUserWritePermission(FileStat stat) {
100-
// First grab the set of permissions for the usr group.
101-
final int permissions = ((stat.mode & 0xFFF) >> 6) & 0x7;
102-
// These values represent all of the octal permission bits that have
103-
// readable and writable permission, though technically if we're missing
104-
// readable we probably didn't make it this far.
105-
return permissions == 6
106-
|| permissions == 7;
107-
}
108-
109-
// Unfortunately the memory file system by default specifies a mode of `0`
110-
// and is used by the majority of our tests. Default to false and only set
111-
// to true when we know it is safe.
112-
static bool checkPermissions = false;
113-
11498
// Initialized by FlutterCommandRunner on startup.
115-
static String get flutterRoot => _flutterRoot;
116-
static String _flutterRoot;
117-
static set flutterRoot(String value) {
118-
if (value == null) {
119-
_flutterRoot = null;
120-
return;
121-
}
122-
if (checkPermissions) {
123-
// Verify that we have writable permission in the flutter root. If not,
124-
// we're liable to crash in unintuitive ways. This can happen if the user
125-
// is using a homebrew or other unofficial channel, or otherwise installs
126-
// Flutter into directory without permissions.
127-
final FileStat binStat = fs.statSync(fs.path.join(value, 'bin'));
128-
final FileStat rootStat = fs.statSync(value);
129-
if (!_hasUserWritePermission(binStat) || !_hasUserWritePermission(rootStat)) {
130-
throwToolExit(
131-
'Warning: Flutter is missing permissions to write files '
132-
'in its installation directory - "$value". '
133-
'Please install Flutter from an official channel in a directory '
134-
'where you have write permissions and that does not require '
135-
'administrative or root access. For more information see '
136-
'https://flutter.dev/docs/get-started/install');
137-
}
138-
}
139-
_flutterRoot = value;
140-
}
99+
static String flutterRoot;
141100

142101
// Whether to cache artifacts for all platforms. Defaults to only caching
143102
// artifacts for the current platform.

packages/flutter_tools/lib/src/runner/flutter_command_runner.dart

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -343,12 +343,6 @@ class FlutterCommandRunner extends CommandRunner<void> {
343343
// We must set Cache.flutterRoot early because other features use it (e.g.
344344
// enginePath's initializer uses it).
345345
final String flutterRoot = topLevelResults['flutter-root'] ?? defaultFlutterRoot;
346-
bool checkPermissions = true;
347-
assert(() {
348-
checkPermissions = false;
349-
return true;
350-
}());
351-
Cache.checkPermissions = checkPermissions;
352346
Cache.flutterRoot = fs.path.normalize(fs.path.absolute(flutterRoot));
353347

354348
// Set up the tooling configuration.
@@ -483,6 +477,10 @@ class FlutterCommandRunner extends CommandRunner<void> {
483477
return EngineBuildPaths(targetEngine: engineBuildPath, hostEngine: engineHostBuildPath);
484478
}
485479

480+
static void initFlutterRoot() {
481+
Cache.flutterRoot ??= defaultFlutterRoot;
482+
}
483+
486484
/// Get the root directories of the repo - the directories containing Dart packages.
487485
List<String> getRepoRoots() {
488486
final String root = fs.path.absolute(Cache.flutterRoot);

packages/flutter_tools/test/cache_test.dart

Lines changed: 4 additions & 44 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,6 @@ import 'dart:async';
66

77
import 'package:file/file.dart';
88
import 'package:file/memory.dart';
9-
import 'package:flutter_tools/src/base/common.dart';
10-
import 'package:flutter_tools/src/base/file_system.dart';
119
import 'package:mockito/mockito.dart';
1210
import 'package:platform/platform.dart';
1311

@@ -42,7 +40,7 @@ void main() {
4240
await Cache.lock();
4341
Cache.checkLockAcquired();
4442
}, overrides: <Type, Generator>{
45-
FileSystem: () => FakeFileSystem(),
43+
FileSystem: () => MockFileSystem(),
4644
});
4745

4846
testUsingContext('should not throw when FLUTTER_ALREADY_LOCKED is set', () async {
@@ -141,50 +139,12 @@ void main() {
141139
expect(flattenNameSubdirs(Uri.parse('http://docs.flutter.io/foo/bar')), 'docs.flutter.io/foo/bar');
142140
expect(flattenNameSubdirs(Uri.parse('https://www.flutter.dev')), 'www.flutter.dev');
143141
}, overrides: <Type, Generator>{
144-
FileSystem: () => FakeFileSystem(),
145-
});
146-
147-
148-
group('Permissions test', () {
149-
MockFileSystem mockFileSystem;
150-
MockFileStat mockFileStat;
151-
152-
setUp(() {
153-
mockFileSystem = MockFileSystem();
154-
mockFileStat = MockFileStat();
155-
when(mockFileSystem.path).thenReturn(fs.path);
156-
Cache.checkPermissions = true;
157-
});
158-
159-
tearDown(() {
160-
Cache.checkPermissions = false;
161-
});
162-
163-
testUsingContext('Throws error if missing usr write permissions in flutterRoot', () {
164-
when(mockFileSystem.statSync(any)).thenReturn(mockFileStat);
165-
when(mockFileStat.mode).thenReturn(344);
166-
167-
expect(() => Cache.flutterRoot = '', throwsA(isInstanceOf<ToolExit>()));
168-
}, overrides: <Type, Generator>{
169-
FileSystem: () => mockFileSystem,
170-
}, initializeFlutterRoot: false);
171-
172-
testUsingContext('Doesnt error if we have usr write permissions in flutterRoot', () {
173-
when(mockFileSystem.statSync(any)).thenReturn(mockFileStat);
174-
when(mockFileStat.mode).thenReturn(493); // 0755 in decimal.
175-
176-
Cache.flutterRoot = '';
177-
}, overrides: <Type, Generator>{
178-
FileSystem: () => mockFileSystem,
179-
}, initializeFlutterRoot: false);
180-
142+
FileSystem: () => MockFileSystem(),
181143
});
182144
}
183145

184-
class MockFileSystem extends Mock implements FileSystem {}
185-
class MockFileStat extends Mock implements FileStat {}
186-
class FakeFileSystem extends ForwardingFileSystem {
187-
FakeFileSystem() : super(MemoryFileSystem());
146+
class MockFileSystem extends ForwardingFileSystem {
147+
MockFileSystem() : super(MemoryFileSystem());
188148

189149
@override
190150
File file(dynamic path) {

packages/flutter_tools/test/commands/analyze_continuously_test.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import 'dart:async';
66

77
import 'package:flutter_tools/src/base/file_system.dart';
88
import 'package:flutter_tools/src/base/os.dart';
9-
import 'package:flutter_tools/src/cache.dart';
109
import 'package:flutter_tools/src/dart/analysis.dart';
1110
import 'package:flutter_tools/src/dart/pub.dart';
1211
import 'package:flutter_tools/src/dart/sdk.dart';
@@ -20,7 +19,7 @@ void main() {
2019
Directory tempDir;
2120

2221
setUp(() {
23-
Cache.flutterRoot = FlutterCommandRunner.defaultFlutterRoot;
22+
FlutterCommandRunner.initFlutterRoot();
2423
tempDir = fs.systemTempDirectory.createTempSync('flutter_analysis_test.');
2524
});
2625

0 commit comments

Comments
 (0)