[flutter_tools] fix pm serve ipv6 linklocal addr issue (#55664)
This commit is contained in:
@@ -58,7 +58,7 @@ class FuchsiaAmberCtl {
|
||||
/// Teaches the amber instance running on [device] about the Fuchsia package
|
||||
/// server accessible via [configUrl].
|
||||
Future<bool> addSrc(FuchsiaDevice device, FuchsiaPackageServer server) async {
|
||||
final String configUrl = '${server.url}/config.json';
|
||||
final String configUrl = '${server.interfaceStrippedUrl}/config.json';
|
||||
final RunResult result =
|
||||
await device.shell('amber_ctl add_src -x -f $configUrl');
|
||||
return result.exitCode == 0;
|
||||
@@ -68,7 +68,7 @@ class FuchsiaAmberCtl {
|
||||
/// Fuchsia package server that it was accessing via [serverUrl].
|
||||
Future<bool> rmSrc(FuchsiaDevice device, FuchsiaPackageServer server) async {
|
||||
final RunResult result =
|
||||
await device.shell('amber_ctl rm_src -n ${server.url}');
|
||||
await device.shell('amber_ctl rm_src -n ${server.interfaceStrippedUrl}');
|
||||
return result.exitCode == 0;
|
||||
}
|
||||
|
||||
@@ -84,7 +84,7 @@ class FuchsiaAmberCtl {
|
||||
/// pkg_resolver repo config, and teaches the pkg_resolver instance running
|
||||
/// on [device] about the [FuchsiaPackageServer].
|
||||
Future<bool> addRepoCfg(FuchsiaDevice device, FuchsiaPackageServer server) async {
|
||||
final String configUrl = '${server.url}/config.json';
|
||||
final String configUrl = '${server.interfaceStrippedUrl}/config.json';
|
||||
final RunResult result =
|
||||
await device.shell('amber_ctl add_repo_cfg -n ${server.name} -f $configUrl');
|
||||
return result.exitCode == 0;
|
||||
|
||||
@@ -111,7 +111,7 @@ class FuchsiaPM {
|
||||
throwToolExit('Fuchsia pm tool not found');
|
||||
}
|
||||
if (isIPv6Address(host.split('%').first)) {
|
||||
host = '[${host.replaceAll('%', '%25')}]';
|
||||
host = '[$host]';
|
||||
}
|
||||
final List<String> command = <String>[
|
||||
globals.fuchsiaArtifacts.pm.path,
|
||||
@@ -181,12 +181,6 @@ class FuchsiaPM {
|
||||
/// }
|
||||
class FuchsiaPackageServer {
|
||||
factory FuchsiaPackageServer(String repo, String name, String host, int port) {
|
||||
// TODO(jonahwilliams): ensure we only receive valid ipv4 or ipv6 InternetAddresses.
|
||||
// Temporary work around to receiving ipv6 addresses with trailing information:
|
||||
// fe80::ec4:7aff:fecc:ea8f%eno2
|
||||
if (host.contains('%')) {
|
||||
host = host.split('%').first;
|
||||
}
|
||||
return FuchsiaPackageServer._(repo, name, host, port);
|
||||
}
|
||||
|
||||
@@ -204,6 +198,14 @@ class FuchsiaPackageServer {
|
||||
/// The URL that can be used by the device to access this package server.
|
||||
String get url => Uri(scheme: 'http', host: _host, port: _port).toString();
|
||||
|
||||
/// The URL that is stripped of interface name if it is an ipv6 address,
|
||||
/// which should be supplied to amber_ctl to configure access to host
|
||||
String get interfaceStrippedUrl => Uri(
|
||||
scheme: 'http',
|
||||
host: (isIPv6Address(_host.split('%').first)) ? '[${_host.split('%').first}]' : _host,
|
||||
port: _port,
|
||||
).toString();
|
||||
|
||||
// The name used to reference the server by fuchsia-pkg:// urls.
|
||||
final String name;
|
||||
|
||||
|
||||
@@ -65,7 +65,7 @@ void main() {
|
||||
'-repo',
|
||||
'<repo>',
|
||||
'-l',
|
||||
'[fe80::ec4:7aff:fecc:ea8f%25eno2]:43819',
|
||||
'[fe80::ec4:7aff:fecc:ea8f%eno2]:43819',
|
||||
])).called(1);
|
||||
}, overrides: <Type, Generator>{
|
||||
FuchsiaArtifacts: () => mockFuchsiaArtifacts,
|
||||
@@ -78,6 +78,11 @@ void main() {
|
||||
|
||||
expect(
|
||||
FuchsiaPackageServer('a', 'b', host, port).url,
|
||||
'http://[fe80::ec4:7aff:fecc:ea8f%25eno2]:23',
|
||||
);
|
||||
|
||||
expect(
|
||||
FuchsiaPackageServer('a', 'b', host, port).interfaceStrippedUrl,
|
||||
'http://[fe80::ec4:7aff:fecc:ea8f]:23',
|
||||
);
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user