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

Shorten encodedGitDir if necessary #1345

Closed
wants to merge 1 commit into from
Closed
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
27 changes: 16 additions & 11 deletions packages/mason/lib/src/bricks_json.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:checked_yaml/checked_yaml.dart';
import 'package:crypto/crypto.dart';
import 'package:http/http.dart' as http;
import 'package:mason/mason.dart';
import 'package:mason/src/git.dart';
Expand Down Expand Up @@ -209,9 +210,7 @@ class BricksJson {

if (!brickYaml.existsSync()) {
if (directory.existsSync()) directory.deleteSync(recursive: true);
final url = gitPath.path.isNotEmpty
? '${gitPath.url}/${gitPath.path}'
: gitPath.url;
final url = gitPath.path.isNotEmpty ? '${gitPath.url}/${gitPath.path}' : gitPath.url;
throw BrickNotFoundException(url);
}

Expand All @@ -234,8 +233,7 @@ class BricksJson {
if (directory.existsSync()) {
final brickYaml = _getBrickYaml(directory);
final name = brick.name ?? brickYaml.name;
final localPath =
_cache[name] ?? canonicalize(p.join(directory.path, gitPath.path));
final localPath = _cache[name] ?? canonicalize(p.join(directory.path, gitPath.path));

if (_cache[name] == null) _cache[name] = localPath;

Expand Down Expand Up @@ -307,8 +305,7 @@ class BricksJson {
p.join(rootDir.path, 'hosted', hostedUri.authority, dirName),
);
final directoryExists = directory.existsSync();
final directoryIsNotEmpty =
directoryExists && directory.listSync(recursive: true).isNotEmpty;
final directoryIsNotEmpty = directoryExists && directory.listSync(recursive: true).isNotEmpty;

/// Use cached version if exists.
if (directoryExists && directoryIsNotEmpty) {
Expand Down Expand Up @@ -385,10 +382,7 @@ class BricksJson {
late final List<Version> versions;
try {
final _versions = body['versions'] as List;
versions = _versions
.map((dynamic v) => Version.parse((v as Map)['version'] as String))
.toList()
..sort(Version.antiprioritize);
versions = _versions.map((dynamic v) => Version.parse((v as Map)['version'] as String)).toList()..sort(Version.antiprioritize);
} catch (_) {
throw BrickResolveVersionException(
'Unable to parse available versions for brick "${brick.name}".',
Expand Down Expand Up @@ -455,6 +449,17 @@ String _encodedGitDir(GitPath git, String commitHash) {
final name = p.basenameWithoutExtension(git.url);
final path = git.url.replaceAll(r'\', '/');
final url = base64.encode(utf8.encode(path));

var output = '${name}_${url}_$commitHash';

if (output.length > 255) {
final maxLength = 255 - commitHash.length - 1;
final hash = sha256.convert(utf8.encode(output)).toString();
final remainder = maxLength - hash.length - 1;
final truncatedNameUrl = '${name}_$url'.substring(0, remainder);
output = '${truncatedNameUrl}_$hash';
}

return '${name}_${url}_$commitHash';
}

Expand Down