From 97e779328dbd9ec00e131ec6069b66f1715c935a Mon Sep 17 00:00:00 2001 From: Greg Spencer Date: Fri, 9 Feb 2018 15:42:51 -0800 Subject: [PATCH] Fix MIME type of uploaded packages. (#14596) When uploading, gsutil is guessing wrong about our desired MIME types. This makes it explicit. --- dev/bots/prepare_package.dart | 25 ++++++++++++++++++++++--- dev/bots/test/prepare_package_test.dart | 14 ++++++++------ 2 files changed, 30 insertions(+), 9 deletions(-) diff --git a/dev/bots/prepare_package.dart b/dev/bots/prepare_package.dart index e5f66eea855..98bb4d7fd9a 100644 --- a/dev/bots/prepare_package.dart +++ b/dev/bots/prepare_package.dart @@ -13,8 +13,7 @@ import 'package:path/path.dart' as path; 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 @@ class ArchivePublisher { } Future _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(['rm', dest], failOk: true); - return _runGsUtil(['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 args = ['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(['-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 412ad14a491..8fe6ebbd545 100644 --- a/dev/bots/test/prepare_package_test.dart +++ b/dev/bots/test/prepare_package_test.dart @@ -211,8 +211,10 @@ void main() { 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 @@ void main() { '''; final Map> calls = >{ 'gsutil rm $gsArchivePath': null, - 'gsutil cp $archivePath $gsArchivePath': null, + 'gsutil cp -h Content-Type:$archiveMime $archivePath $gsArchivePath': null, 'gsutil cat $gsJsonPath': [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 @@ void main() { // 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": {'));