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

fix(mason): bug where long path leads to error on windows #759

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
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
8 changes: 5 additions & 3 deletions packages/mason/lib/src/bricks_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -440,11 +440,13 @@ class BricksJson {
if (environment.containsKey('MASON_CACHE')) {
return Directory(environment['MASON_CACHE']!);
} else if (isWindows) {
const longPathPrefix = r'\\?\';
final appData = environment['APPDATA']!;
final appDataCacheDir = Directory(p.join(appData, 'Mason', 'Cache'));
if (appDataCacheDir.existsSync()) return Directory(appDataCacheDir.path);
final appDataCacheDir =
Directory(longPathPrefix + p.join(appData, 'Mason', 'Cache'));
if (appDataCacheDir.existsSync()) return appDataCacheDir;
final localAppData = environment['LOCALAPPDATA']!;
return Directory(p.join(localAppData, 'Mason', 'Cache'));
return Directory(longPathPrefix + p.join(localAppData, 'Mason', 'Cache'));
} else {
return Directory(p.join(environment['HOME']!, '.mason-cache'));
}
Expand Down
4 changes: 2 additions & 2 deletions packages/mason/lib/src/path.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import 'package:path/path.dart' as p;
/// However, it does not change the ASCII case of the path.
/// See https://github.com/dart-lang/path/issues/102.
String canonicalize(String path) {
return p.normalize(p.absolute(path)).replaceAll(r'\', '/');
return p.normalize(p.absolute(path));
}

/// Normalizes the [path].
String normalize(String path) => p.normalize(path).replaceAll(r'\', '/');
String normalize(String path) => p.normalize(path);
10 changes: 8 additions & 2 deletions packages/mason/test/src/bricks_json_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -717,7 +717,10 @@ environment:
)..createSync(recursive: true);
BricksJson.testEnvironment = {'APPDATA': directory.path};
BricksJson.testIsWindows = true;
expect(BricksJson.rootDir.path, equals(appDataCacheDirectory.path));
expect(
BricksJson.rootDir.path,
equals('${r'\\?\'}${appDataCacheDirectory.path}'),
);
});

test(
Expand All @@ -732,7 +735,10 @@ environment:
'LOCALAPPDATA': directory.path
};
BricksJson.testIsWindows = true;
expect(BricksJson.rootDir.path, equals(appDataCacheDirectory.path));
expect(
BricksJson.rootDir.path,
equals('${r'\\?\'}${appDataCacheDirectory.path}'),
);
});

test('uses HOME by default', () {
Expand Down
Loading