Skip to content

Commit 97e7793

Browse files
authored
Fix MIME type of uploaded packages. (flutter#14596)
When uploading, gsutil is guessing wrong about our desired MIME types. This makes it explicit.
1 parent d64efe9 commit 97e7793

File tree

2 files changed

+30
-9
lines changed

2 files changed

+30
-9
lines changed

dev/bots/prepare_package.dart

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,8 +13,7 @@ import 'package:path/path.dart' as path;
1313
import 'package:process/process.dart';
1414
import 'package:platform/platform.dart' show Platform, LocalPlatform;
1515

16-
const String chromiumRepo =
17-
'https://chromium.googlesource.com/external/github.com/flutter/flutter';
16+
const String chromiumRepo = 'https://chromium.googlesource.com/external/github.com/flutter/flutter';
1817
const String githubRepo = 'https://github.com/flutter/flutter.git';
1918
const String mingitForWindowsUrl = 'https://storage.googleapis.com/flutter_infra/mingit/'
2019
'603511c649b00bbef0a6122a827ac419b656bc19/mingit.zip';
@@ -475,8 +474,28 @@ class ArchivePublisher {
475474
}
476475

477476
Future<String> _cloudCopy(String src, String dest) async {
477+
// We often don't have permission to overwrite, but
478+
// we have permission to remove, so that's what we do.
478479
await _runGsUtil(<String>['rm', dest], failOk: true);
479-
return _runGsUtil(<String>['cp', src, dest]);
480+
String mimeType;
481+
if (dest.endsWith('.tar.xz')) {
482+
mimeType = 'application/x-gtar';
483+
}
484+
if (dest.endsWith('.zip')) {
485+
mimeType = 'application/zip';
486+
}
487+
if (dest.endsWith('.json')) {
488+
mimeType = 'application/json';
489+
}
490+
final List<String> args = <String>['cp'];
491+
// Use our preferred MIME type for the files we care about
492+
// and let gsutil figure it out for anything else.
493+
if (mimeType != null) {
494+
args.addAll(<String>['-h', 'Content-Type:$mimeType']);
495+
}
496+
args.add(src);
497+
args.add(dest);
498+
return _runGsUtil(args);
480499
}
481500
}
482501

dev/bots/test/prepare_package_test.dart

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -211,8 +211,10 @@ void main() {
211211

212212
test('calls the right processes', () async {
213213
final String releasesName = 'releases_$platformName.json';
214-
final String archivePath = path.join(tempDir.absolute.path, 'output_archive');
215-
final String gsArchivePath = 'gs://flutter_infra/releases/dev/$platformName/output_archive';
214+
final String archiveName = platform.isWindows ? 'archive.zip' : 'archive.tar.xz';
215+
final String archiveMime = platform.isWindows ? 'application/zip' : 'application/x-gtar';
216+
final String archivePath = path.join(tempDir.absolute.path, archiveName);
217+
final String gsArchivePath = 'gs://flutter_infra/releases/dev/$platformName/$archiveName';
216218
final String jsonPath = path.join(tempDir.absolute.path, releasesName);
217219
final String gsJsonPath = 'gs://flutter_infra/releases/$releasesName';
218220
final String releasesJson = '''{
@@ -237,13 +239,13 @@ void main() {
237239
''';
238240
final Map<String, List<ProcessResult>> calls = <String, List<ProcessResult>>{
239241
'gsutil rm $gsArchivePath': null,
240-
'gsutil cp $archivePath $gsArchivePath': null,
242+
'gsutil cp -h Content-Type:$archiveMime $archivePath $gsArchivePath': null,
241243
'gsutil cat $gsJsonPath': <ProcessResult>[new ProcessResult(0, 0, releasesJson, '')],
242244
'gsutil rm $gsJsonPath': null,
243-
'gsutil cp $jsonPath $gsJsonPath': null,
245+
'gsutil cp -h Content-Type:application/json $jsonPath $gsJsonPath': null,
244246
};
245247
processManager.fakeResults = calls;
246-
final File outputFile = new File(path.join(tempDir.absolute.path, 'output_archive'));
248+
final File outputFile = new File(path.join(tempDir.absolute.path, archiveName));
247249
assert(tempDir.existsSync());
248250
final ArchivePublisher publisher = new ArchivePublisher(
249251
tempDir,
@@ -264,7 +266,7 @@ void main() {
264266
// Make sure new data is added.
265267
expect(contents, contains('"dev": "$testRef"'));
266268
expect(contents, contains('"$testRef": {'));
267-
expect(contents, contains('"${platformName}_archive": "dev/$platformName/output_archive"'));
269+
expect(contents, contains('"${platformName}_archive": "dev/$platformName/$archiveName"'));
268270
// Make sure existing entries are preserved.
269271
expect(contents, contains('"6da8ec6bd0c4801b80d666869e4069698561c043": {'));
270272
expect(contents, contains('"f88c60b38c3a5ef92115d24e3da4175b4890daba": {'));

0 commit comments

Comments
 (0)