Unverified Commit 7e1a0d40 authored by Christopher Fujino's avatar Christopher Fujino Committed by GitHub

[flutter_tools] delete entitlements files after copying to macos build dir (#126875)

Fixes https://github.com/flutter/flutter/issues/126705
parent 34371894
...@@ -1004,6 +1004,19 @@ class ArtifactUpdater { ...@@ -1004,6 +1004,19 @@ class ArtifactUpdater {
@visibleForTesting @visibleForTesting
final List<File> downloadedFiles = <File>[]; final List<File> downloadedFiles = <File>[];
/// These filenames, should they exist after extracting an archive, should be deleted.
static const Set<String> _denylistedBasenames = <String>{'entitlements.txt', 'without_entitlements.txt'};
void _removeDenylistedFiles(Directory directory) {
for (final FileSystemEntity entity in directory.listSync(recursive: true)) {
if (entity is! File) {
continue;
}
if (_denylistedBasenames.contains(entity.basename)) {
entity.deleteSync();
}
}
}
/// Download a zip archive from the given [url] and unzip it to [location]. /// Download a zip archive from the given [url] and unzip it to [location].
Future<void> downloadZipArchive( Future<void> downloadZipArchive(
String message, String message,
...@@ -1120,6 +1133,7 @@ class ArtifactUpdater { ...@@ -1120,6 +1133,7 @@ class ArtifactUpdater {
_deleteIgnoringErrors(tempFile); _deleteIgnoringErrors(tempFile);
continue; continue;
} }
_removeDenylistedFiles(location);
return; return;
} }
} }
......
...@@ -74,6 +74,49 @@ void main() { ...@@ -74,6 +74,49 @@ void main() {
expect(fileSystem.file('out/test/foo.txt'), isNot(exists)); expect(fileSystem.file('out/test/foo.txt'), isNot(exists));
}); });
testWithoutContext('ArtifactUpdater will delete any denylisted files from the outputDirectory', () async {
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
final MemoryFileSystem fileSystem = MemoryFileSystem.test();
final BufferLogger logger = BufferLogger.test();
final Directory tempStorage = fileSystem.currentDirectory.childDirectory('temp');
final String localZipPath = tempStorage.childFile('test.zip').path;
File? desiredArtifact;
File? entitlementsFile;
File? nestedWithoutEntitlementsFile;
operatingSystemUtils.unzipCallbacks[localZipPath] = (Directory outputDirectory) {
desiredArtifact = outputDirectory.childFile('artifact.bin')..createSync();
entitlementsFile = outputDirectory.childFile('entitlements.txt')..createSync();
nestedWithoutEntitlementsFile = outputDirectory
.childDirectory('dir')
.childFile('without_entitlements.txt')
..createSync(recursive: true);
};
final ArtifactUpdater artifactUpdater = ArtifactUpdater(
fileSystem: fileSystem,
logger: logger,
operatingSystemUtils: operatingSystemUtils,
platform: testPlatform,
httpClient: FakeHttpClient.any(),
tempStorage: tempStorage..createSync(),
allowedBaseUrls: <String>['http://test.zip'],
);
// entitlements file cached from before the tool had a denylist
final File staleEntitlementsFile = fileSystem.file('out/path/to/entitlements.txt')..createSync(recursive: true);
expect(staleEntitlementsFile, exists);
await artifactUpdater.downloadZipArchive(
'test message',
Uri.parse('http://test.zip'),
fileSystem.currentDirectory.childDirectory('out'),
);
expect(logger.statusText, contains('test message'));
expect(desiredArtifact, exists);
expect(entitlementsFile, isNot(exists));
expect(nestedWithoutEntitlementsFile, isNot(exists));
expect(staleEntitlementsFile, isNot(exists));
});
testWithoutContext('ArtifactUpdater will not validate the md5 hash if the ' testWithoutContext('ArtifactUpdater will not validate the md5 hash if the '
'x-goog-hash header is present but missing an md5 entry', () async { 'x-goog-hash header is present but missing an md5 entry', () async {
final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils(); final FakeOperatingSystemUtils operatingSystemUtils = FakeOperatingSystemUtils();
...@@ -491,15 +534,25 @@ class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils { ...@@ -491,15 +534,25 @@ class FakeOperatingSystemUtils extends Fake implements OperatingSystemUtils {
int failures = 0; int failures = 0;
final bool windows; final bool windows;
/// A mapping of zip [file] paths to callbacks that receive the [targetDirectory].
///
/// Use this to have [unzip] generate an arbitrary set of [FileSystemEntity]s
/// under [targetDirectory].
final Map<String, void Function(Directory)> unzipCallbacks = <String, void Function(Directory)>{};
@override @override
void unzip(File file, Directory targetDirectory) { void unzip(File file, Directory targetDirectory) {
if (failures > 0) { if (failures > 0) {
failures -= 1; failures -= 1;
throw Exception(); throw Exception();
} }
if (unzipCallbacks.containsKey(file.path)) {
unzipCallbacks[file.path]!(targetDirectory);
} else {
targetDirectory.childFile(file.fileSystem.path.basenameWithoutExtension(file.path)) targetDirectory.childFile(file.fileSystem.path.basenameWithoutExtension(file.path))
.createSync(); .createSync();
} }
}
@override @override
void unpack(File gzippedTarFile, Directory targetDirectory) { void unpack(File gzippedTarFile, Directory targetDirectory) {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment