Fix MIME type of uploaded packages. (#14596)
When uploading, gsutil is guessing wrong about our desired MIME types. This makes it explicit.
diff --git a/dev/bots/prepare_package.dart b/dev/bots/prepare_package.dart
index e5f66ee..98bb4d7 100644
--- a/dev/bots/prepare_package.dart
+++ b/dev/bots/prepare_package.dart
@@ -13,8 +13,7 @@
import 'package:process/process.dart';
import 'package:platform/platform.dart' show Platform, LocalPlatform;
-const String chromiumRepo =
- 'https://chromium.googlesource.com/external/github.com/flutter/flutter';
+const String chromiumRepo = 'https://chromium.googlesource.com/external/github.com/flutter/flutter';
const String githubRepo = 'https://github.com/flutter/flutter.git';
const String mingitForWindowsUrl = 'https://storage.googleapis.com/flutter_infra/mingit/'
'603511c649b00bbef0a6122a827ac419b656bc19/mingit.zip';
@@ -475,8 +474,28 @@
}
Future<String> _cloudCopy(String src, String dest) async {
+ // We often don't have permission to overwrite, but
+ // we have permission to remove, so that's what we do.
await _runGsUtil(<String>['rm', dest], failOk: true);
- return _runGsUtil(<String>['cp', src, dest]);
+ String mimeType;
+ if (dest.endsWith('.tar.xz')) {
+ mimeType = 'application/x-gtar';
+ }
+ if (dest.endsWith('.zip')) {
+ mimeType = 'application/zip';
+ }
+ if (dest.endsWith('.json')) {
+ mimeType = 'application/json';
+ }
+ final List<String> args = <String>['cp'];
+ // Use our preferred MIME type for the files we care about
+ // and let gsutil figure it out for anything else.
+ if (mimeType != null) {
+ args.addAll(<String>['-h', 'Content-Type:$mimeType']);
+ }
+ args.add(src);
+ args.add(dest);
+ return _runGsUtil(args);
}
}
diff --git a/dev/bots/test/prepare_package_test.dart b/dev/bots/test/prepare_package_test.dart
index 412ad14..8fe6ebb 100644
--- a/dev/bots/test/prepare_package_test.dart
+++ b/dev/bots/test/prepare_package_test.dart
@@ -211,8 +211,10 @@
test('calls the right processes', () async {
final String releasesName = 'releases_$platformName.json';
- final String archivePath = path.join(tempDir.absolute.path, 'output_archive');
- final String gsArchivePath = 'gs://flutter_infra/releases/dev/$platformName/output_archive';
+ final String archiveName = platform.isWindows ? 'archive.zip' : 'archive.tar.xz';
+ final String archiveMime = platform.isWindows ? 'application/zip' : 'application/x-gtar';
+ final String archivePath = path.join(tempDir.absolute.path, archiveName);
+ final String gsArchivePath = 'gs://flutter_infra/releases/dev/$platformName/$archiveName';
final String jsonPath = path.join(tempDir.absolute.path, releasesName);
final String gsJsonPath = 'gs://flutter_infra/releases/$releasesName';
final String releasesJson = '''{
@@ -237,13 +239,13 @@
''';
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
'gsutil rm $gsArchivePath': null,
- 'gsutil cp $archivePath $gsArchivePath': null,
+ 'gsutil cp -h Content-Type:$archiveMime $archivePath $gsArchivePath': null,
'gsutil cat $gsJsonPath': <ProcessResult>[new ProcessResult(0, 0, releasesJson, '')],
'gsutil rm $gsJsonPath': null,
- 'gsutil cp $jsonPath $gsJsonPath': null,
+ 'gsutil cp -h Content-Type:application/json $jsonPath $gsJsonPath': null,
};
processManager.fakeResults = calls;
- final File outputFile = new File(path.join(tempDir.absolute.path, 'output_archive'));
+ final File outputFile = new File(path.join(tempDir.absolute.path, archiveName));
assert(tempDir.existsSync());
final ArchivePublisher publisher = new ArchivePublisher(
tempDir,
@@ -264,7 +266,7 @@
// Make sure new data is added.
expect(contents, contains('"dev": "$testRef"'));
expect(contents, contains('"$testRef": {'));
- expect(contents, contains('"${platformName}_archive": "dev/$platformName/output_archive"'));
+ expect(contents, contains('"${platformName}_archive": "dev/$platformName/$archiveName"'));
// Make sure existing entries are preserved.
expect(contents, contains('"6da8ec6bd0c4801b80d666869e4069698561c043": {'));
expect(contents, contains('"f88c60b38c3a5ef92115d24e3da4175b4890daba": {'));